Stanford NLP:如何对单个词进行词法化? [英] Stanford NLP: How to lemmatize single word?
本文介绍了Stanford NLP:如何对单个词进行词法化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何注释一个句子并获得每个单词的引理,但是如果我只想对一个 单词进行词义化,我不知道该怎么做.我尝试过
I know how I can annotate a sentence and get the lemma of each word but I don't know how to do it if I just want to lemmatize a single word. I tried
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
.
but the tokenAnnotation
has only one TextAnnotation
key which means list
will be null
here.
那么我该如何对单个词进行词素化?
So how can I lemmatize a single word?
推荐答案
有两种选择:您可以通过StanfordCoreNLP
管道为Annotation
对象添加注释:
There are two options: you can either annotate you Annotation
object through a StanfordCoreNLP
pipeline:
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:
The other option is to use the SimpleCoreNLP API:
String tokenLemma = new Sentence("wedding").lemma(0);
这篇关于Stanford NLP:如何对单个词进行词法化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文