예제 #1
0
 /** Force a refresh of all names assigned to graph nodes. */
 @SuppressWarnings("unchecked")
 void refreshNodeNames(boolean showCode, boolean abbreviate) {
   for (Iterator<Tuple> tuples = getNodes().tuples(); tuples.hasNext(); ) {
     Tuple t = tuples.next();
     ResolvedConceptReference rcr = (ResolvedConceptReference) t.get("RCR");
     if (rcr != null) {
       String code = showCode ? rcr.getConceptCode() : null;
       String desc =
           rcr.getEntityDescription() != null ? rcr.getEntityDescription().getContent() : null;
       t.set("name", getNodeName(code, desc, abbreviate, "\n"));
     }
   }
 }
예제 #2
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};
  }