public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
      // first clear the character buffer
      m_sbuf.delete(0, m_sbuf.length());

      if (qName.equals(GRAPH)) {
        // parse directedness default
        String edef = atts.getValue(EDGEDEF);
        m_directed = DIRECTED.equalsIgnoreCase(edef);
        m_graphid = atts.getValue(ID);
      } else if (qName.equals(KEY)) {
        if (!inSchema) {
          error(
              "\""
                  + KEY
                  + "\" elements can not"
                  + " occur after the first node or edge declaration.");
        }
        m_for = atts.getValue(FOR);
        m_id = atts.getValue(ID);
        m_name = atts.getValue(ATTRNAME);
        m_type = atts.getValue(ATTRTYPE);
      } else if (qName.equals(NODE)) {
        schemaCheck();

        m_row = m_nodes.addRow();

        String id = atts.getValue(ID);
        m_nodeMap.put(id, new Integer(m_row));
        m_table = m_nodes;
      } else if (qName.equals(EDGE)) {
        schemaCheck();

        m_row = m_edges.addRow();

        // do not use the id value
        //                String id = atts.getValue(ID);
        //                if ( id != null ) {
        //                    if ( !m_edges.canGetString(ID) )
        //                        m_edges.addColumn(ID, String.class);
        //                    m_edges.setString(m_row, ID, id);
        //                }
        m_edges.setString(m_row, SRCID, atts.getValue(SRC));
        m_edges.setString(m_row, TRGID, atts.getValue(TRG));

        // currently only global directedness is used
        // ignore directed edge value for now
        //                String dir = atts.getValue(DIRECTED);
        //                boolean d = m_directed;
        //                if ( dir != null ) {
        //                    d = dir.equalsIgnoreCase("false");
        //                }
        //                m_edges.setBoolean(m_row, DIRECTED, d);
        m_table = m_edges;
      } else if (qName.equals(DATA)) {
        m_key = atts.getValue(KEY);
      }
    }
  public Graph toGraph() {
    Table edgeTable = new Table();
    Table nodeTable = new Table();
    HashMap<String, Integer> unique = new HashMap<String, Integer>();

    edgeTable.addColumn("Node1", int.class);
    edgeTable.addColumn("Node2", int.class);
    nodeTable.addColumn("key", int.class);
    nodeTable.addColumn("name", String.class);
    nodeTable.addColumn("type", String.class);
    nodeTable.addColumn("indeterminate", int.class);

    int idx = 0;
    for (Protein prot : minProteins.values()) {
      int row = nodeTable.addRow();
      unique.put(prot.getName(), idx);
      nodeTable.setInt(row, "key", idx++);
      nodeTable.setString(row, "name", prot.getName());
      nodeTable.setString(row, "type", "protein");
      nodeTable.setInt(row, "indeterminate", 0);
    }

    for (Peptide pep : minPeptides.values()) {
      int row = nodeTable.addRow();
      unique.put(pep.getSequence(), idx);
      nodeTable.setInt(row, "key", idx++);
      nodeTable.setString(row, "name", pep.getSequence());
      nodeTable.setString(row, "type", "peptide");
      if (pep.getIndeterminateType() == PeptideIndeterminacyType.NONE) {
        nodeTable.setInt(row, "indeterminate", 0);
      } else {
        nodeTable.setInt(row, "indeterminate", 1);
      }
    }

    for (Protein prot : minProteins.values()) {
      int id1 = unique.get(prot.getName());
      for (String pep : prot.getPeptides()) {
        int id2 = unique.get(pep);
        int row = edgeTable.addRow();
        edgeTable.setInt(row, "Node1", id1);
        edgeTable.setInt(row, "Node2", id2);
      }
    }
    Graph g = new Graph(nodeTable, edgeTable, false, "key", "Node1", "Node2");
    // System.err.println(g.getEdgeCount());
    return g;
  }
Exemple #3
0
 private Table populateTable(Table t, Graph g) {
   for (final Iterator it = g.nodes(); it.hasNext(); ) {
     final Node n = (Node) it.next();
     t.addRow();
     for (int i = 0; i < n.getColumnCount(); i++) {
       t.set(t.getRowCount() - 1, i, n.get(i));
     }
     t.set(t.getRowCount() - 1, UNIQUE_INDEX_COLUMN_NAME, new Integer(t.getRowCount()));
   }
   return t;
 }
Exemple #4
0
 /**
  * Adds a menu item to the fisheye menu.
  *
  * @param name the menu label to use
  * @param action the ActionListener to notify when the item is clicked The prefuse VisualItem
  *     corresponding to this menu item will be returned by the ActionEvent's getSource() method.
  */
 public void addMenuItem(String name, ActionListener listener) {
   int row = m_items.addRow();
   m_items.set(row, LABEL, name);
   m_items.set(row, ACTION, listener);
 }
 /**
  * Adds a edge.
  *
  * @param node1
  * @param node2
  * @param weight
  */
 public void addEdge(long node1, long node2, double weight) {
   int row = edges.addRow();
   edges.set(row, EHEADERS[0], node1);
   edges.set(row, EHEADERS[1], node2);
   edges.set(row, EHEADERS[2], weight);
 }
 /**
  * Adds a node.
  *
  * @param id
  * @param name
  * @param picture
  */
 public void addNode(long id, String name, String picture) {
   int row = nodes.addRow();
   nodes.set(row, NHEADERS[0], id);
   nodes.set(row, NHEADERS[1], name);
   nodes.set(row, NHEADERS[2], picture);
 }
Exemple #7
0
  /*
   * Input data from the "Place_Column_Name" is obtained from the original table & Lookups
   * are made to appropriate maps. After processing all rows, the new output table is
   * returned having original data and 2 new columns for Latitude & Longitude.
   */
  public static Table compute(
      String locationColumnName, Table originalTable, LogService logger, Geocoder geocoder) {
    /*
     * Create Blank new output table using the schema from the original table.
     */
    Table outputTable = originalTable.getSchema().instantiate();
    String outputTableLatitudeColumnName =
        TableUtilities.formNonConflictingNewColumnName(
            originalTable.getSchema(), LATITUDE_COLUMN_NAME_SUGGESTIONS);
    String outputTableLongitudeColumnName =
        TableUtilities.formNonConflictingNewColumnName(
            originalTable.getSchema(), LONGITUDE_COLUMN_NAME_SUGGESTIONS);

    outputTable.addColumn(outputTableLatitudeColumnName, Double.class);
    outputTable.addColumn(outputTableLongitudeColumnName, Double.class);

    logger.log(
        LogService.LOG_INFO,
        String.format(
            "Latitude & Longitude values added to %s & %s, respectively.",
            outputTableLatitudeColumnName, outputTableLongitudeColumnName));

    int locationColumnNumber = originalTable.getColumnNumber(locationColumnName);
    int latitudeColumnNumber = outputTable.getColumnNumber(outputTableLatitudeColumnName);
    int longitudeColumnNumber = outputTable.getColumnNumber(outputTableLongitudeColumnName);
    Map<String, Geolocation> geocodedAddressToGeoLocation = new HashMap<String, Geolocation>();
    FrequencyMap<String> failedFrequency = new FrequencyMap<String>(true);
    Iterator<?> locationColumnIterator = originalTable.iterator();
    while (locationColumnIterator.hasNext()) {
      int currentRowNumber = Integer.parseInt(locationColumnIterator.next().toString());

      /* Start geocoding */
      Geolocation geolocation = DEFAULT_NO_LOCATION_VALUE;
      String currentLocation = "";
      Object currentLocationObject = originalTable.get(currentRowNumber, locationColumnNumber);
      if (currentLocationObject != null) {
        currentLocation = currentLocationObject.toString();
        String currentLocationUppercase = currentLocation.toUpperCase();

        /* Avoid re-geocoding the same place */
        if (geocodedAddressToGeoLocation.containsKey(currentLocationUppercase)) {
          geolocation = geocodedAddressToGeoLocation.get(currentLocationUppercase);
          if (geolocation == DEFAULT_NO_LOCATION_VALUE) {
            failedFrequency.add(currentLocation);
          }
        } else {
          try {
            geolocation = geocoder.geocodingFullForm(currentLocationUppercase);
          } catch (GeoCoderException e) {
            try {
              /* Try lookup in the abbreviation */
              geolocation = geocoder.geocodingAbbreviation(currentLocationUppercase);
            } catch (GeoCoderException e1) {
              /* No result is found */
              failedFrequency.add(currentLocation);
            }
          }

          /* Add to geocoded map */
          geocodedAddressToGeoLocation.put(currentLocationUppercase, geolocation);
        }
      } else {
        failedFrequency.add(currentLocation);
      }

      /*
       * Add the new row to the new table
       * by copying the original row & then adding 2 new columns to it.
       */
      outputTable.addRow();
      TableUtilities.copyTableRow(currentRowNumber, currentRowNumber, outputTable, originalTable);
      outputTable.set(currentRowNumber, latitudeColumnNumber, geolocation.getLatitude());
      outputTable.set(currentRowNumber, longitudeColumnNumber, geolocation.getLongitude());
    }

    /* Warning user about failure */
    if (!failedFrequency.isEmpty()) {
      printWarningMessage(logger, locationColumnName, failedFrequency);
    }

    /* Show statistic information */
    int totalRow = originalTable.getRowCount();
    NumberFormat numberFormat = NumberFormat.getInstance();
    logger.log(
        LogService.LOG_INFO,
        String.format(
            "Successfully geocoded %s out of %s locations to geographic coordinates",
            numberFormat.format(totalRow - failedFrequency.sum()), numberFormat.format(totalRow)));
    return outputTable;
  }