问题描述
我正在与斯坦福大学NLP的开放式注解者见面.但是,选项openie.resolve_coref在我的输入文本中不起作用.我想使用openie生成具有三重引用的三元组.我该怎么做?这段代码是从网站Stanford复制而来的,我添加了以下代码行:props.setProperty("openie.resolve_coref","true");
I am meeting the openie annotator of Stanford NLP. However the option openie.resolve_coref don't work in my input text.I want use openie for generate triples with coreference resolved. How I can to do this?This code was copied of site Stanford and I added the line:props.setProperty("openie.resolve_coref", "true");
Properties props = new Properties();
props.setProperty("openie.resolve_coref", "true");
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,parse,natlog,ner,coref,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate an example document.
String text = "Obama was born in Hawaii. He is our president.";
Annotation doc = new Annotation(textoInput);
pipeline.annotate(doc);
// Loop over sentences in the document
int sentNo = 0;
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
System.out.println("Sentence #" + ++sentNo + ": " + sentence.get(CoreAnnotations.TextAnnotation.class));
// Print SemanticGraph
System.out.println(sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class).toString(SemanticGraph.OutputFormat.LIST));
// 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 CON=" +
triple.subjectLemmaGloss() + "\t REL=" +
triple.relationLemmaGloss() + "\t CON=" +
triple.objectLemmaGloss());
}
// Alternately, to only run e.g., the clause splitter:
List<SentenceFragment> clauses = new OpenIE(props).clausesInSentence(sentence);
for (SentenceFragment clause : clauses) {
System.out.println(clause.parseTree.toString(SemanticGraph.OutputFormat.LIST));
}
System.out.println();
该过程将产生以下三个结果:
The process results in this triple:
-
1.0奥巴马在夏威夷忍受
1.0 Obama be bear in Hawaii
1.0奥巴马要忍受
1.0 他是我们的总统->应该是->奥巴马是我们的总统
1.0 he be we president -> Should be -> Obama be we president
推荐答案
编辑:此错误在3.7.0+版本中也已修复
EDIT: this bug is also fixed in versions 3.7.0+
这是3.6.0版本中的一个错误,该错误已在GitHub版本中修复.它将在下一个版本中修复,或者您可以从 CoreNLP GitHub页面手动更新代码和模型jars -您可以下载最新的模型,并使用ant jar
构建代码jar.
This is a bug in the 3.6.0 release which is fixed in the GitHub version. It'll be fixed in the next release, or you can manually update the code and model jars from the CoreNLP GitHub page -- you can download the latest models, and build the code jar with ant jar
.
我的输出是:
Sentence #1: Obama was born in Hawaii.
root(ROOT-0, born-3)
nsubjpass(born-3, Obama-1)
auxpass(born-3, was-2)
case(Hawaii-5, in-4)
nmod:in(born-3, Hawaii-5)
punct(born-3, .-6)
1.0 CON=Obama REL=be bear in CON=Hawaii
1.0 CON=Obama REL=be CON=bear
[main] INFO edu.stanford.nlp.naturalli.ClauseSplitter - Loading clause splitter from edu/stanford/nlp/models/naturalli/clauseSearcherModel.ser.gz ... done [0.43 seconds]
root(ROOT-0, born-3)
nsubjpass(born-3, Obama-1)
auxpass(born-3, was-2)
case(Hawaii-5, in-4)
nmod:in(born-3, Hawaii-5)
Sentence #2: He is our president.
root(ROOT-0, president-4)
nsubj(president-4, He-1)
cop(president-4, is-2)
nmod:poss(president-4, our-3)
punct(president-4, .-5)
1.0 CON=Obama REL=be CON=we president
[main] INFO edu.stanford.nlp.naturalli.ClauseSplitter - Loading clause splitter from edu/stanford/nlp/models/naturalli/clauseSearcherModel.ser.gz ... done [0.45 seconds]
root(ROOT-0, president-4)
nsubj(president-4, He-1)
cop(president-4, is-2)
nmod:poss(president-4, our-3)
这篇关于带有选项openie.resolve_coref的斯坦福OpenIE不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!