public Graph<String, String> createGraph() { // edu.uci.ics.jung.graph.Tree<String,String> treeGraph = new DelegateTree<String,String>(); DirectedOrderedSparseMultigraph<String, String> treeGraph = new DirectedOrderedSparseMultigraph<String, String>(); Tree root = this.model.getRoot(); treeGraph.addVertex("Root"); vertexMap.put("Root", root); addTree(treeGraph, root, "Root"); return new DelegateForest<String, String>(treeGraph); // return treeGraph; }
private void addTree( DirectedOrderedSparseMultigraph<String, String> treeGraph, Tree node, String parentName) { Iterator<Edge> e = node.childIterator(); double edgeWeightSum = 0.0d; while (e.hasNext()) { Edge edge = e.next(); Tree child = edge.getChild(); edgeWeightSum += child.getSubtreeFrequencySum(); } e = node.childIterator(); while (e.hasNext()) { Edge edge = e.next(); Tree child = edge.getChild(); SplitCondition condition = edge.getCondition(); String childName = vertexFactory.create(); String edgeName = edgeFactory.create(); vertexMap.put(childName, child); edgeMap.put(edgeName, condition); edgeStrengthMap.put(edgeName, child.getSubtreeFrequencySum() / edgeWeightSum); treeGraph.addEdge(edgeName, parentName, childName); addTree(treeGraph, child, childName); } }