use of edu.stanford.nlp.ling.HasLemma in project CoreNLP by stanfordnlp.
the class SpanishXMLTreeReader method buildWordNode.
/**
* Build a parse tree node corresponding to the word in the given XML node.
*/
private Tree buildWordNode(Node root) {
Element eRoot = (Element) root;
String posStr = getPOS(eRoot);
posStr = treeNormalizer.normalizeNonterminal(posStr);
String lemma = eRoot.getAttribute(ATTR_LEMMA);
String word = getWord(eRoot);
String leafStr = treeNormalizer.normalizeTerminal(word);
Tree leafNode = treeFactory.newLeaf(leafStr);
if (leafNode.label() instanceof HasWord)
((HasWord) leafNode.label()).setWord(leafStr);
if (leafNode.label() instanceof HasLemma && lemma != null)
((HasLemma) leafNode.label()).setLemma(lemma);
List<Tree> kids = new ArrayList<>();
kids.add(leafNode);
Tree t = treeFactory.newTreeNode(posStr, kids);
if (t.label() instanceof HasTag)
((HasTag) t.label()).setTag(posStr);
return t;
}
use of edu.stanford.nlp.ling.HasLemma in project CoreNLP by stanfordnlp.
the class TreeLemmatizer method transformTree.
@Override
public Tree transformTree(Tree t) {
Morphology morphology = new Morphology();
List<TaggedWord> tagged = null;
int index = 0;
for (Tree leaf : t.getLeaves()) {
Label label = leaf.label();
if (label == null) {
continue;
}
String tag;
if (!(label instanceof HasTag) || ((HasTag) label).tag() == null) {
if (tagged == null) {
tagged = t.taggedYield();
}
tag = tagged.get(index).tag();
} else {
tag = ((HasTag) label).tag();
}
if (!(label instanceof HasLemma)) {
throw new IllegalArgumentException("Got a tree with labels which do not support lemma");
}
((HasLemma) label).setLemma(morphology.lemma(label.value(), tag, true));
++index;
}
return t;
}
Aggregations