core-nlp共指分辨率:重新共同引用

问题描述 投票:0回答:1

我一直在尝试使用core-nlp共同参考分辨率系统。系统按照教程中的说明工作。以下是相同的代码:

public static void main(String[] args) throws Exception {
    Annotation document = new Annotation("Barack Obama was born in Hawaii.  He is the president. Obama was elected in 2008.");
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,mention,coref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    pipeline.annotate(document);
    System.out.println("---");
    System.out.println("coref chains");
    for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) {
      System.out.println("\t" + cc);
    }

哪个输出:

CHAIN3-["Barack Obama" in sentence 1, "He" in sentence 1]

我想要得到的是一张显示的地图

Key | Value
He : Barack Obama
Obama: Barack Obama

是否有内置方法来实现这一点,还是我必须对此进行后处理(不仅仅是Map)?

java stanford-nlp
1个回答
1
投票

目前还没有真正的代码。这是一个片段,将打印出提及光泽,位置信息和规范提及:

for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) {
    CorefChain.CorefMention representativeMention = cc.getRepresentativeMention();
    for (CorefChain.CorefMention cm : cc.getMentionsInTextualOrder()) {
      String position = "sentence num: "+cm.sentNum+" position: "+cm.startIndex;
      System.out.println(cm.mentionSpan + "\t" + position + "\t" + representativeMention.mentionSpan);
}

}

© www.soinside.com 2019 - 2024. All rights reserved.