コード例 #1
0
ファイル: Dichotomize.java プロジェクト: cns-iu/nwb
  public Data[] execute() {
    Graph graph = (Graph) data[0].getData();
    String attribute = (String) parameters.get("attribute");
    String comparator = (String) parameters.get("comparator");
    double cutoff = ((Double) parameters.get("cutoff")).doubleValue();

    // empty tables with the same schemas as the originals
    Table nodeTable = graph.getNodeTable().getSchema().instantiate();
    Table edgeTable = graph.getEdgeTable().getSchema().instantiate();

    // keep all nodes
    Iterator nodes = graph.getNodeTable().iterator();
    while (nodes.hasNext()) {
      nodeTable.addTuple(graph.getNodeTable().getTuple(((Integer) nodes.next()).intValue()));
    }

    // keep all edges matching the criteria
    Iterator edges = graph.getEdgeTable().iterator();
    while (edges.hasNext()) {
      Tuple tuple = graph.getEdgeTable().getTuple(((Integer) edges.next()).intValue());
      Object value = tuple.get(attribute);
      if (value != null) {
        if (passes(comparator, ((Number) value).doubleValue(), cutoff)) {
          edgeTable.addTuple(tuple);
        }
      }
    }

    Graph resultGraph =
        new Graph(
            nodeTable,
            edgeTable,
            graph.isDirected(),
            graph.getNodeKeyField(),
            graph.getEdgeSourceField(),
            graph.getEdgeTargetField());

    Data result = new BasicData(resultGraph, Graph.class.getName());
    Dictionary metadata = result.getMetadata();
    metadata.put(
        DataProperty.LABEL, "Only edges with " + attribute + " " + comparator + " " + cutoff);
    metadata.put(DataProperty.PARENT, this.data[0]);
    metadata.put(DataProperty.TYPE, DataProperty.NETWORK_TYPE);

    return new Data[] {result};
  }
コード例 #2
0
  /*
   * Test method for 'prefuse.Visualization.getSourceData(String)'
   */
  @Test
  public void testGetSourceData() {
    Assert.assertEquals(m_t, m_vis.getSourceData("t"));
    Assert.assertEquals(m_t, m_vt0.getSourceData());

    Assert.assertEquals(m_g, m_vis.getSourceData("g"));
    Assert.assertEquals(m_g.getNodeTable(), m_vis.getSourceData("g.nodes"));
    Assert.assertEquals(m_g.getEdgeTable(), m_vis.getSourceData("g.edges"));
    Assert.assertEquals(m_g.getNodeTable(), m_vn0.getSourceData());
  }