重建斯坦福CoreNLP句子

时间:2015-03-09 19:33:15

标签: java stanford-nlp

使用 CoreNLP 我试图对带注释的文档进行一些更改。

 Properties props = new Properties();
 props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
 pipeline = new StanfordCoreNLP(props);

 Annotation document = new Annotation(input);
 pipeline.annotate(document);

 //TODO (1) change parsed input
 //TODO (2) String reconstructedSentence = ...

我想知道是否有任何标准方法来更新已解析的树并从此树重建新句子?

1 个答案:

答案 0 :(得分:0)

最终我最终得到了简单的解决方案。会看到它有多强大。

StringBuilder builder = new StringBuilder();
for(CoreLabel label : document.get(CoreAnnotations.TokensAnnotation.class)) {
    if(builder.length() != 0 && needSpaceBefore(label)) {
        builder.append(" ");
    }
    builder.append(processLabel(label));
}
return builder.toString();
相关问题