stanford-nlp - 斯坦福 NLP : How to lemmatize single word?

标签 stanford-nlp

我知道如何注释一个句子并获得每个单词的引理,但如果我只想对单个单词进行引理,我不知道该怎么做。我试过

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/

相关文章:

python - 使用 Stanza 和 CoreNLPClient 提取名词短语

java - 如何将我的词典添加到斯坦福标记器中?

java - 配置 Java 在 R 版本 3.5.0 中使用以及使用 rJava 和 coreNLP 库的问题

java - Stanford CoreNLP 中的详细情绪评分

nlp - Stanford coreNLP - 忽略撇号的拆分词

java - SemgrexPattern 引理属性似乎不起作用

java - 序列化斯坦福解析器对象

java - 使用斯坦福解析器查找名词短语

nlp - 自定义 NER 和 POS 标记

java - import edu.stanford.nlp.pipeline.StanfordCoreNLP 无法解析?