public List<TreeGraphNode> getStanfordTreeGraphNodes(DependencyForm form) {
if (this.nodes != null) return this.nodes;
this.nodes = new ArrayList<TreeGraphNode>();
// Add an explicit root node
nodes.add(new TreeGraphNode(ROOT_LABEL));
List<WordLemmaTag> labels = getStanfordWordLemmaTags();
for (WordLemmaTag curToken : labels) {
// Create the tree node
TreeGraphNode treeNode = new TreeGraphNode(curToken);
treeNode.label().setTag(curToken.tag());
/**
* Caution, the order to call is to first setWord(), then setlemma()
* From the Stanford source code:
*
public void setWord(String word) {
set(WordAnnotation.class, word);
// pado feb 09: if you change the word, delete the lemma.
remove(LemmaAnnotation.class);
}
public void setLemma(String lemma) {
set(LemmaAnnotation.class, lemma);
}
*/
treeNode.label().setWord(curToken.word());
treeNode.label().setLemma(curToken.lemma());
nodes.add(treeNode);
}
List<AgigaTypedDependency> agigaDeps = getAgigaDeps(form);
for (AgigaTypedDependency agigaDep : agigaDeps) {
// Add one, since the tokens are zero-indexed but the TreeGraphNodes are one-indexed
TreeGraphNode gov = nodes.get(agigaDep.getGovIdx() + 1);
TreeGraphNode dep = nodes.get(agigaDep.getDepIdx() + 1);
// Add gov/dep to TreeGraph
gov.addChild(dep);
dep.setParent(gov);
require(dep.parent() == gov);
}
return nodes;
}