lemmas = null;
}
//Terminals can have multiple tokens (MWEs). Make these into a
//flat structure for now.
Tree t = null;
List<Tree> kids = new ArrayList<Tree>();
if(leafToks.size() > 1) {
for (int i = 0; i < leafToks.size(); ++i) {
String tok = leafToks.get(i);
String s = treeNormalizer.normalizeTerminal(tok);
List<Tree> leafList = new ArrayList<Tree>();
Tree leafNode = treeFactory.newLeaf(s);
if(leafNode.label() instanceof HasWord)
((HasWord) leafNode.label()).setWord(s);
if (leafNode.label() instanceof CoreLabel && lemmas != null) {
((CoreLabel) leafNode.label()).setLemma(lemmas.get(i));
}
if(leafNode.label() instanceof HasContext) {
((HasContext) leafNode.label()).setOriginalText(morph);
}
if (leafNode.label() instanceof HasCategory) {
((HasCategory) leafNode.label()).setCategory(subcat);
}
leafList.add(leafNode);
Tree posNode = treeFactory.newTreeNode(MISSING_POS, leafList);
if(posNode.label() instanceof HasTag)
((HasTag) posNode.label()).setTag(MISSING_POS);
kids.add(posNode);
}
t = treeFactory.newTreeNode(MISSING_PHRASAL, kids);
} else {
String leafStr = treeNormalizer.normalizeTerminal(leafToks.get(0));
Tree leafNode = treeFactory.newLeaf(leafStr);
if (leafNode.label() instanceof HasWord)
((HasWord) leafNode.label()).setWord(leafStr);
if (leafNode.label() instanceof CoreLabel && lemmas != null) {
((CoreLabel) leafNode.label()).setLemma(lemmas.get(0));
}
if (leafNode.label() instanceof HasContext) {
((HasContext) leafNode.label()).setOriginalText(morph);
}
if (leafNode.label() instanceof HasCategory) {
((HasCategory) leafNode.label()).setCategory(subcat);
}
kids.add(leafNode);
t = treeFactory.newTreeNode(posStr, kids);
if (t.label() instanceof HasTag) ((HasTag) t.label()).setTag(posStr);
}
return t;
}
List<Tree> kids = new ArrayList<Tree>();
for(Node childNode = eRoot.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
if(childNode.getNodeType() != Node.ELEMENT_NODE) continue;
Tree t = getTreeFromXML(childNode);
if(t == null) {
System.err.printf("%s: Discarding empty tree (root: %s)%n", this.getClass().getName(),childNode.getNodeName());
} else {
kids.add(t);
}
}
// MWEs have a label with a
String rootLabel = eRoot.getNodeName().trim();
boolean isMWE = rootLabel.equals("w") && eRoot.hasAttribute(ATTR_POS);
if(isMWE)
rootLabel = eRoot.getAttribute(ATTR_POS).trim();
Tree t = (kids.size() == 0) ? null : treeFactory.newTreeNode(treeNormalizer.normalizeNonterminal(rootLabel), kids);
if(t != null && isMWE)
t = postProcessMWE(t);
return t;