我在list of annotation中找不到任何与bag-of-words相关的东西。我发现有一个用于获取词袋的注解类,我假设它被用作:
coreMap.get(CoreAnnotations.BagOfWordsAnnotation.class);但是我不知道我应该启用哪个注释器。到目前为止,我已经尝试过:
tokenize, ssplit, pos, lemma, ner, parse, sentiment, natlog, openie但没那么走运。
如何在Stanford NLP解析器中使用BagOfWordsAnnotation?
发布于 2017-07-17 23:06:33
这不就是使用tokenize注解的输出吗?或者,更复杂一点的lemmatisation输出?(这有点取决于您的用例),例如:
Properties props;
props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma");
pipeline = new StanfordCoreNLP(props);
public static List<String> lemmatize(String documentText)
{
List<String> lemmas = new LinkedList<String>();
Annotation document = new Annotation(documentText);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
lemmas.add(token.get(LemmaAnnotation.class));
}
}
return lemmas;
}我从来没有听说过这个注释器,如果它存在,我会发现有点令人惊讶,因为它基本上是标记化的,可能会增加一些停用词剥离,你可以很容易地自己做,或者使用其他(较少面向NLP和更多面向IR的)包,如Lucene。
https://stackoverflow.com/questions/45076328
复制相似问题