我知道如何注释一个句子并获得每个单词的引理,但如果我只想对单个单词进行引理,我不知道该怎么做。我试过
Annotation tokenAnnotation = new Annotation("wedding");
List<CoreMap> list = tokenAnnotation.get(SentencesAnnotation.class);
String tokenLemma = list
.get(0).get(TokensAnnotation.class)
.get(0).get(LemmaAnnotation.class);
但
tokenAnnotation
只有一个 TextAnnotation
表示 list
的键将是 null
这里。那么我怎样才能对一个词进行词形还原呢?
最佳答案
有两种选择:您可以为您添加注释 Annotation
对象通过 StanfordCoreNLP
管道:
StanfordCoreNLP pipeline = new StanfordCoreNLP(new Properties(){{
setProperty("annotators", "tokenize,ssplit,pos,lemma");
}});
Annotation tokenAnnotation = new Annotation("wedding");
pipeline.annotate(tokenAnnotation); // necessary for the LemmaAnnotation to be set.
List<CoreMap> list = tokenAnnotation.get(SentencesAnnotation.class);
String tokenLemma = list
.get(0).get(TokensAnnotation.class)
.get(0).get(LemmaAnnotation.class);
另一种选择是使用 SimpleCoreNLP API:
String tokenLemma = new Sentence("wedding").lemma(0);
关于stanford-nlp - 斯坦福 NLP : How to lemmatize single word?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963203/