java - CoreNLP进行ssplit后如何获取句子的原文?

标签 java stanford-nlp

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/

相关文章:

stanford-nlp - 如何让Stanford CoreNLP Semgrex找到与NMOD的关系?

JAVA:如何将 Gazettes 与 Stanford NLP 结合使用?

java - 您将如何测试静态方法 URLEncoder.encode?

java - 在 Java 中使用函数式接口(interface)的真实示例

java - Java 中的序列化问题 (Android Studio)

stanford-nlp - 如何指示 NER SUTime 解决 future 问题?

java - 提取中心名词

java - 测量 Web 应用程序 session 资源消耗

java - 如何使用共享数据库(JPA)同步多个客户端?

python - NLTK 无法找到 stanford-postagger.jar!设置 CLASSPATH 环境变量