Stanford OpenIE with option openie.resolve_coref don't work

試著忘記壹切 提交于 2019-12-10 22:48:36

问题


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 Obama be bear in Hawaii

  • 1.0 Obama be bear

  • 1.0 he be we president -> Should be -> Obama be we president


回答1:


EDIT: this bug is also fixed in versions 3.7.0+

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.

My output is:

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)


来源:https://stackoverflow.com/questions/35921678/stanford-openie-with-option-openie-resolve-coref-dont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!