}
parent.setNodeTags(tags);
parent.setHeadIndex(parse.getHeadIndex());
Parse[] subtrees = parse.getChildren();
FSArray children = new FSArray(jcas, subtrees.length);
for(int i = 0; i < subtrees.length; i++){
Parse subtree = subtrees[i];
if(subtree.getChildCount() == 1 && subtree.getChildren()[0].getChildCount() == 0){
// pre-terminal case - now we can set the type (POS tag) and point the parent in the right direction
TerminalTreebankNode term = root.getTerminals(subtree.getHeadIndex());
term.setNodeType(subtree.getType());
children.set(i,term);
term.setParent(parent);
term.addToIndexes();
}else{
try{
TreebankNode child = new TreebankNode(jcas);
child.setParent(parent);
children.set(i, child);
recursivelyCreateStructure(jcas, child, subtree, root);
child.addToIndexes();
}catch(NullPointerException e){
System.err.println("MaxentParserWrapper Error: " + e);
throw new AnalysisEngineProcessException();
}
}
}
// after we've built up all the children we can fill in the span of the parent.
parent.setBegin(((TreebankNode)children.get(0)).getBegin());
parent.setEnd(((TreebankNode)children.get(subtrees.length-1)).getEnd());
parent.setChildren(children);
// parent.addToIndexes();
}