我知道我可以标注一个句子,让每个单词的引理,但我不知道该怎么做,如果我只是想lemmatize一个单一的词.我试过了
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);
Run Code Online (Sandbox Code Playgroud)
但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);
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用 SimpleCoreNLP API:
String tokenLemma = new Sentence("wedding").lemma(0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1835 次 |
| 最近记录: |