2016-03-25 16 views
-1

Stanford CoreNLP kullanıyorum. ÖrneğinStanford CoreNLP Çekirdeklerinde Çekirdek set ve temsil değerleri nasıl belirlenir?

: Ben algılamak ve benim giriş metninde her CorefChain için "Coreference seti" s ve "temsili söz" ler tespit etmek gerekir Giriş: Obama, 1996 yılında Illinois eyalet senatosuna seçildi ve sunulduğu Orada sekiz yıl. 2004 yılında Illinois'den ABD Senatosu'na kayıtlı bir çoğunluk tarafından seçildi ve Şubat 2007'de Başkanlık için adaylığını açıkladı.

Çıktı:

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

Ancak, programlı belirlemek ve "Coreference kümesi" denir Yukarıdaki çıkışı algılamak gerekir: "Pretty Print" ile aşağıda çıktısını alabilirsiniz. (Ben gibi tüm çiftleri tespit etmek gerekir demek: "O" -> "Obama")

Not: My baz kodudur aşağıda (o http://stanfordnlp.github.io/CoreNLP/coref.html dan) Bir:

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 

cevap

2

Bir CorefChain bu bilgiyi içerir.

Örneğin bir alabilirsiniz:

List<CorefChain.CorefMention> 

bu yöntemi kullanarak:

cc.getMentionsInTextualOrder(); 

Bu söz konusu kümenin belgede size tüm CorefChain.CorefMention en verecektir.

Bu yöntemle temsili söz alabilirsiniz:

cc.getRepresentativeMention(); 

A CorefChain.CorefMention COREF kümede belirli bir söz temsil eder. Sen (cümledeki numarayı söz cümle sayısı) böyle bir CorefChain.CorefMention tam dize ve pozisyonu olarak bilgi alabilirsiniz:

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

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

CorefChain için javadoc link

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

: İşte

CorefChain.CorefMention için javadoc link

İlgili konular