2016-03-25 5 views
-1

私はスタンフォードCoreNLPを使用しています。例えばスタンフォードCoreNLPコアレファレンスでCoreferenceセットと代表的な記述を特定する方法は?

:sおよび「代表言及」の各CorefChainのための私の入力テキスト内の「設定共参照」私は検出して特定する必要があり 入力: オバマ氏は、1996年にイリノイ州の上院議員に当選し、役立ちましたそこに8年間。 2004年には、イリノイ州の米上院議員の大多数が選出され、2007年2月に大統領選挙が発表されました。

出力:

**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"** 

は、しかし、私はプログラム的に識別し、「共参照セット」と呼ばれている上記の出力を検出する必要があります:「プリティ印刷」とは、私は以下の出力を得ることができます。

注:私の基本コードは(それが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 

答えて

2

- :(>「オバマ」「彼」私は私のようなすべてのペアを特定する必要があります意味します) CorefChainにはその情報が含まれています。

List<CorefChain.CorefMention> 

この方法を使用して:あなたが得ることができる。例えば

cc.getMentionsInTextualOrder(); 

これは、あなたのすべてのCorefChain.CorefMentionのドキュメント内のその特定のクラスタ用を提供します。

あなたはこの方法では、代表的言及を得ることができます:

cc.getRepresentativeMention(); 

A 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

関連する問題