斯坦福大学NLP:如何使单个单词变形?

dis*_*ame 5 stanford-nlp

我知道我可以标注一个句子,让每个单词的引理,但我不知道该怎么做,如果我只是想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这里.

那么我怎样才能将一个单词列为单词呢?

Gab*_*eli 3

有两种选择:您可以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)