CoreNLP 的标记化会更改句子文本。将由空格分隔的标记拼接在一起并不是真正的重建。如果句子包含圆括号和其他标点符号,事情就会变得复杂。请参阅下面的代码块。
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit");
pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(paragraph);
pipeline.annotate(document);
List<CoreMap>sentences = document.get(SentencesAnnotation.class);
List<String> sentenceList = new ArrayList<>();
for (CoreMap sentence : sentences)
{
//How to get the original text of sentence?
}
最佳答案
回答我自己的问题。这很容易。插入以下行代替问题代码块中的注释。
String sentenceString = Sentence.listToOriginalTextString(sentence.get(TokensAnnotation.class));
关于java - CoreNLP进行ssplit后如何获取句子的原文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32465099/