I use the Stanford parser for my implementation. I would like to use the tree of a sentence in order to extract various information.
I used the code in : Get certain nodes out of a Parse Tree:
I have my CoreMap sentence and the corresponding tree :
Tree sentenceTree= sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
for (Tree sentenceTree: t) {
String pos = sentenceTree.label().value();
String wd = sentenceTree.firstChild().label().value();
Integer wdIndex = ??
CoreLabel token = sentence.get(CoreAnnotations.TokensAnnotation.class).get(wdIndex);
}
I was not able to extract the lemma, does anyone have an idea how to do it ?
I tried the following code and it works but it generates some warnings and is not very clean neither:
Annotation a = new Annotation("geese");
ss.pipeline.annotate(a);
CoreMap se = a.get(CoreAnnotations.SentencesAnnotation.class).get(0);
CoreLabel token = se.get(CoreAnnotations.TokensAnnotation.class).get(0);
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
System.out.println(lemma); // goose
Has anyone any advice ?
Thank you!