public Tree<String> getDependencyTree(Constituent parseTreeRoot) { // for each parse non-terminal, starting from the root, find the head. // Make a dependency arc from the all the other children to the head // child. if (TreeView.isLeaf(parseTreeRoot)) return new Tree<>(parseTreeRoot.getTokenizedSurfaceForm()); Constituent headWord = headFinder.getHeadWord(parseTreeRoot); Constituent headChild = headFinder.getHeadChild(parseTreeRoot); Tree<String> rootTree = new Tree<>(headWord.getTokenizedSurfaceForm()); List<Tree<String>> dependentTrees = new ArrayList<>(); for (Relation childEdge : parseTreeRoot.getOutgoingRelations()) { Constituent child = childEdge.getTarget(); if (child.equals(headChild)) { rootTree = getDependencyTree(child); } else { dependentTrees.add(getDependencyTree(child)); } } rootTree.addSubtrees(dependentTrees); return rootTree; }
public Tree<String> getDependencyTree(Constituent parseTreeRoot) { // for each parse non-terminal, starting from the root, find the head. // Make a dependency arc from the all the other children to the head // child. if (TreeView.isLeaf(parseTreeRoot)) return new Tree<>(parseTreeRoot.getTokenizedSurfaceForm()); Constituent headWord = headFinder.getHeadWord(parseTreeRoot); Constituent headChild = headFinder.getHeadChild(parseTreeRoot); Tree<String> rootTree = new Tree<>(headWord.getTokenizedSurfaceForm()); List<Tree<String>> dependentTrees = new ArrayList<>(); for (Relation childEdge : parseTreeRoot.getOutgoingRelations()) { Constituent child = childEdge.getTarget(); if (child.equals(headChild)) { rootTree = getDependencyTree(child); } else { dependentTrees.add(getDependencyTree(child)); } } rootTree.addSubtrees(dependentTrees); return rootTree; }