Java 核心nlp共指解析:重新映射共指
我一直在尝试使用核心nlp共同参考解析系统。该系统的工作原理如本教程所述。以下是相同的代码:Java 核心nlp共指解析:重新映射共指,java,stanford-nlp,Java,Stanford Nlp,我一直在尝试使用核心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 pro
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
是否有一个内置的方法来实现这一点,或者我必须对此进行后期处理(不仅仅是地图)?目前还没有真正的代码。下面是一个片段,它将打印出提及光泽度、位置信息和规范提及:
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);
}
}