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); }
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; }
@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); } }); }
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())); } }
public void connectNodes(String sourceNodeName, String destNodeName, Relationship rel) throws DBException { _graph.addEdge(sourceNodeName, destNodeName, rel); }
public boolean contains(String nodeName) { return _graph.hasNode(nodeName); }
public void addNode(String nodeName) { if (!contains(nodeName)) _graph.addNode(nodeName); }
public Relationship getRelationship(String src, String dest) { return _graph.getEdgeLabel(src, dest); }
public boolean hasEdge(String src, String dest) { return _graph.hasEdge(src, dest); }
public String toString() { return _graph.toString(); }