-1

我正在使用斯坦福 CoreNLP。我需要检测并识别输入文本中每个 CorefChain 的“共指集”和“代表性提及”:

For example: Input: Obama was elected to the Illinois state senate in 1996 and served there for eight years. 2004年,他以创纪录的多数席位从伊利诺伊州选出,并于2007年2月宣布了他的总统候选人资格。

输出:使用“Pretty Print”我可以得到以下输出:

**Coreference set:
(2,4,[4,5]) -> (1,1,[1,2]), that is: "he" -> "Obama"

(2,24,[24,25]) -> (1,1,[1,2]), that is: "his" -> "Obama"

(3,22,[22,23]) -> (1,1,[1,2]), that is: "Obama" -> "Obama"**

但是,我需要以编程方式识别和检测上面的输出,称为“共指集”。(我的意思是我需要识别所有对,例如:“he”->“Obama”)

注意:我的基本代码如下(来自http://stanfordnlp.github.io/CoreNLP/coref.html):

import edu.stanford.nlp.hcoref.CorefCoreAnnotations;
import edu.stanford.nlp.hcoref.data.CorefChain;
import edu.stanford.nlp.hcoref.data.Mention;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
import java.util.Properties;
public class CorefExample {

public static void main(String[] args) throws Exception {

Annotation document = new Annotation("Obama was elected to the Illinois state senate in 1996 and served there for eight years. In 2004, he was elected by a record majority to the U.S. Senate from Illinois and, in February 2007, announced his candidacy for President.");
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);
}
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
  System.out.println("---");
  System.out.println("mentions");
  for (Mention m : sentence.get(CorefCoreAnnotations.CorefMentionsAnnotation.class)) {
    System.out.println("\t"+m);
     }
   }
  }
 }

 ///// Any Idea? THANK YOU in ADVANCE
4

1 回答 1

2

CorefChain 包含该信息。

例如,您可以获得:

List<CorefChain.CorefMention> 

通过使用这种方法:

cc.getMentionsInTextualOrder();

这将为您提供该特定集群的文档中的所有 CorefChain.CorefMention。

您可以使用此方法获得代表性提及:

cc.getRepresentativeMention();

CorefChain.CorefMention 代表 coref 集群中的特定提及。您可以从 CorefChain.CorefMention 获取完整字符串和位置等信息(句号,句子中的提及号):

for (CorefChain.CorefMention cm : cc.getMentionsInTextualOrder()) {
    String textOfMention = cm.mentionSpan;
    IntTuple positionOfMention = cm.position;
}

这是 CorefChain 的 javadoc 的链接:

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/dcoref/CorefChain.html

这是 CorefChain.CorefMention 的 javadoc 的链接:

http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/dcoref/CorefChain.CorefMention.html

于 2016-03-27T07:33:54.780 回答