示例#1
0
  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
  public SelfLoopsParallelEdges(final Graph g) {
    HashSet selfLoops = new HashSet();
    HashSet parallelEdges = new HashSet();
    HashMap edges = new HashMap();
    boolean directed = g.isDirected();
    Edge edg;

    for (Iterator it = g.edges(); it.hasNext(); ) {
      edg = (Edge) it.next();

      this.addEdge(edg, directed, selfLoops, parallelEdges, edges);
    }

    selfLoopInfo = this.calculateSelfLoops(selfLoops);
    parallelEdgeInfo = this.calculateParallelEdges(parallelEdges, edges);

    selfLoops = null;
    edges = null;
    parallelEdges = null;
    edg = null;
  }