예제 #1
0
  public void save(SQLiteAccess query) throws DBException {
    if (query.hasTable("node")) query.dropTable("node");
    if (query.hasTable("edge")) query.dropTable("edge");

    Relation nodeRelation = new Relation();
    nodeRelation.add(new DataTypeBase("id", TypeName.INTEGER, true, true));
    nodeRelation.add(new DataTypeBase("name", TypeName.STRING));
    query.createTable("node", nodeRelation);

    Relation edgeRelation = new Relation();
    edgeRelation.add(new DataTypeBase("id", TypeName.INTEGER, true, true));
    edgeRelation.add(new DataTypeBase("src", TypeName.INTEGER));
    edgeRelation.add(new DataTypeBase("dest", TypeName.INTEGER));
    edgeRelation.add(new DataTypeBase("relationship", TypeName.INTEGER));
    query.createTable("edge", edgeRelation);

    Vector<NodeData> nodeList = new Vector<NodeData>();
    for (int nodeID : _graph.getNodeIDSet()) {
      nodeList.add(new NodeData(nodeID, _graph.getNodeLabel(nodeID)));
    }

    Vector<EdgeData> edgeList = new Vector<EdgeData>();
    for (Edge edge : _graph.getEdgeSet()) {
      edgeList.add(
          new EdgeData(
              _graph.getEdgeID(edge),
              edge.getSourceNodeID(),
              edge.getDestNodeID(),
              _graph.getEdgeLabel(edge)));
    }

    for (NodeData node : nodeList) query.insert("node", node);
    for (EdgeData edge : edgeList) query.insert("edge", edge);
  }
예제 #2
0
  public Set<String> getRootNodeNameSet() {
    TreeSet<String> rootNodeSet = new TreeSet<String>();

    for (String node : _graph.getNodeLabelSet()) {
      // if this node has no incoming edges
      if (_graph.getInEdgeSet(node).size() == 0) rootNodeSet.add(node);
    }

    return rootNodeSet;
  }
예제 #3
0
  @SuppressWarnings("unchecked")
  public List<String> destinationOf(String nodeName) {
    Collection<Integer> nodeIDSet = _graph.getDestNodeIDSetOf(_graph.getNodeID(nodeName));

    return CollectionUtil.collect(
        nodeIDSet,
        new Functor<Integer, String>() {
          public String apply(Integer nodeID) {
            return _graph.getNodeLabel(nodeID);
          }
        });
  }
예제 #4
0
  public void load(SQLiteAccess query) throws DBException {

    TreeSet<NodeData> nodeList = CollectionUtil.sort(query.amoebaQuery(NodeData.class, "node"));
    TreeSet<EdgeData> edgeList = CollectionUtil.sort(query.amoebaQuery(EdgeData.class, "edge"));

    for (NodeData node : nodeList) {
      _graph.addNode(node.getName());
    }
    for (EdgeData edge : edgeList) {
      _graph.addEdge(
          new Edge(edge.getSrc(), edge.getDest()), EdgeData.translate(edge.getRelationship()));
    }
  }
예제 #5
0
 public void connectNodes(String sourceNodeName, String destNodeName, Relationship rel)
     throws DBException {
   _graph.addEdge(sourceNodeName, destNodeName, rel);
 }
예제 #6
0
 public boolean contains(String nodeName) {
   return _graph.hasNode(nodeName);
 }
예제 #7
0
 public void addNode(String nodeName) {
   if (!contains(nodeName)) _graph.addNode(nodeName);
 }
예제 #8
0
 public Relationship getRelationship(String src, String dest) {
   return _graph.getEdgeLabel(src, dest);
 }
예제 #9
0
 public boolean hasEdge(String src, String dest) {
   return _graph.hasEdge(src, dest);
 }
예제 #10
0
 public String toString() {
   return _graph.toString();
 }