gpt4 book ai didi

java - core-nlp 共指解析 : remaping co-references

转载 作者:行者123 更新时间:2023-12-01 08:54:48 26 4
gpt4 key购买 nike

我一直在尝试使用 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]

我想要得到的是一张显示的 map

Key | Value
He : Barack Obama
Obama: Barack Obama

是否有内置方法可以实现此目的,或者我是否必须对此进行后处理(不仅仅是 map )?

最佳答案

目前还没有真正的代码。下面是一个片段,它将打印出提及注释、位置信息和规范提及:

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);
}

}

关于java - core-nlp 共指解析 : remaping co-references,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42108716/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com