您从Stanford NLP网站上获得的代码将对text变量执行所有注释。为了执行特定的注释,您必须相应地更改代码。
要执行令牌化,这就足够了
Properties props = new Properties();props.put("annotators", "tokenize");StanfordCoreNLP pipeline = new StanfordCoreNLP(props);Annotation document = new Annotation(text);pipeline.annotate(document);for (CoreLabel token: document.get(TokensAnnotation.class)) { String word = token.get(TextAnnotation.class);}如果注释器不包含Sentence Splitter(“ ssplit”),则此行代码将返回Null
document.get(SentencesAnnotation.class);
因此,您遇到了NullPointerException。



