if(node.getHead() == null){
// do absolutely nothing with this -- it covers the whole sentence and has no useful info
continue;
}
SimpleTree curTree = null;
SimpleTree headTree = null;
if(!node2tree.containsKey(node)){
curTree = SimpleTree.fromString(String.format("(%s %s)", node.getDeprel(), node.getCoveredText()));
node2tree.put(node, curTree);
}else{
curTree = node2tree.get(node);
}
if(curTree.parent == null && node.getHead().getHead() != null){
if(node2tree.containsKey(node.getHead())){
headTree = node2tree.get(node.getHead());
}else{
headTree = SimpleTree.fromString(String.format("(%s %s)", node.getHead().getDeprel(), node.getHead().getCoveredText()));
node2tree.put(node.getHead(), headTree);
}
curTree.parent = headTree.children.get(0);
headTree.children.get(0).addChild(curTree);
}
}
ConllDependencyNode highestHead = null;
// take the set of input annotations and the corresponding labels and insert them into the SimpleTree
for(int i = 0; i < annotations.length; i++){
// get the node representing the head of this annotation
List<ConllDependencyNode> coveredNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, annotations[i]);
if(coveredNodes == null || coveredNodes.size() == 0) continue;
ConllDependencyNode headNode = DependencyUtility.getNominalHeadNode(coveredNodes);
// is this the highest node of all the annotations we're looking at?
if(highestHead == null || (distanceFromRoot(headNode) < distanceFromRoot(highestHead))){
highestHead = headNode;
}
// String realCat = node2tree.get(headNode).children.get(0).cat;
// have to do this so that we have a placeholder so we can lowercase tokens, then insert the upper-case CONCEPT signifier token later.
// node2tree.get(headNode).children.get(0).cat = "conceptplaceholder";
SimpleTree insertionPoint = node2tree.get(headNode);
SimpleTree insertingTree = new SimpleTree(insertionPoint.cat);
insertionPoint.cat = labels[i];
insertingTree.children = insertionPoint.children;
insertingTree.children.get(0).parent = insertingTree;
insertionPoint.children = new ArrayList<SimpleTree>();
insertionPoint.addChild(insertingTree);
insertingTree.parent = insertionPoint;
// node2tree.get(headNode).children.get(0).cat = realCat;
}
SimpleTree localTree = node2tree.get(highestHead.getHead().getHead() == null ? highestHead : highestHead.getHead());
String treeStr = localTree.toString();
treeStr = treeStr.replaceAll("\\(([^\\(]+) \\)", "($1 nil)").toLowerCase();
return treeStr;
}