2017-11-04 49 views
0

該網站建議我可以用幾個標誌 https://nlp.stanford.edu/software/openie.html如何在stanford-nlp程序中提供標誌選項?

但如何使用它,我試圖做這種方式

import edu.stanford.nlp.ie.util.RelationTriple; 
import edu.stanford.nlp.ling.CoreAnnotations; 
import edu.stanford.nlp.pipeline.Annotation; 
import edu.stanford.nlp.pipeline.StanfordCoreNLP; 
import edu.stanford.nlp.naturalli.NaturalLogicAnnotations; 
import edu.stanford.nlp.util.CoreMap; 

import java.util.Collection; 
import java.util.Properties; 

/** 
* A demo illustrating how to call the OpenIE system programmatically. 
*/ 
public class OpenIEDemo { 

public static void main(String[] args) throws Exception { 
// Create the Stanford CoreNLP pipeline 
Properties props = new Properties(); 
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie"); 
props.setProperty("openieformat","ollie"); 
props.setProperty("openieresolve_coref","1"); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

// Annotate an example document. 
Annotation doc = new Annotation("Obama was born in Hawaii. He is our president."); 
pipeline.annotate(doc); 

// Loop over sentences in the document 
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) { 
    // Get the OpenIE triples for the sentence 
    Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class); 
    // Print the triples 
    for (RelationTriple triple : triples) { 
    System.out.println(triple.confidence + "\t" + 
     triple.subjectLemmaGloss() + "\t" + 
     triple.relationLemmaGloss() + "\t" + 
     triple.objectLemmaGloss()); 
    } 
} 
} 
} 

我已經加入

props.setProperty("openieformat","ollie"); 
props.setProperty("openieresolve_coref","1"); 

但它不工作

回答

0

對於StanfordCoreNLP,單個註釋器的標記/屬性設置爲annotator.flag名稱。而布爾標誌的值爲「false」或「true」。所以,你有什麼是接近正確的,但需要:

props.setProperty("openie.format","ollie"); props.setProperty("openie.resolve_coref","true");

+0

有一件事我發現之後,我認爲會得再添註釋dcoref,爲完成工作 – Shashwattrivedi

相關問題