我是Stanford CoreNLP的新手。我有几个句子想键入强制转换那些字符串句子到列表并将其设置为annotation.set(CoreAnnotations.SentencesAnnotation.class, sentences);
有办法完成上述任务吗?
您必须填写一个List<CoreMap>
对象,下面的代码将提示您如何逐句填写。但是还有其他字段需要填写,你可以在这里找到完整的代码
List<String> yourSentences = ...;
int tokenOffset = 0;
List<CoreMap> sentences = new ArrayList<CoreMap>();
for(String s: yourSentences ){
List<CoreLabel> tokenizedSentence = tokenizerFactory.getTokenizer(
new StringReader(s)).tokenize();
Annotation sentence = new Annotation(text.trim());
sentence.set(CoreAnnotations.TokensAnnotation.class, tokenizedSentence);
tokenOffset += sentenceTokens.size();
sentence.set(CoreAnnotations.TokenEndAnnotation.class, tokenOffset);
sentence.set(CoreAnnotations.SentenceIndexAnnotation.class, sentences.size());
sentences.add(sentence);
}