【问题标题】:Can't implement options for Stanford CoreNLP's OpenIE annotator无法实现斯坦福 CoreNLP 的 OpenIE 注释器的选项
【发布时间】:2018-07-17 07:25:55
【问题描述】:

我已经在 Eclipse 中成功运行了 Stanford CoreNLP 注释器,但在实现 OpenIE 注释器提供的选项时遇到了问题。最初我认为这只是 openie.filelist 选项的错误,并尝试以不同的方式指定文件路径,但后来我注意到其他选项,例如 openie.format,也不起作用。

这是下面包含的代码。

package main.java.com.nlptools.corenlp;
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.*;

public class OpenIETest {

  public static void main(String[] args) throws Exception {
    // Pipeline property setup
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
    props.setProperty("openie.format", "reverb");
    props.setProperty("openie.filelist", "src/OpenIETestDoc.txt");
    // Create corenlp pipeline
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // Build and annotate an example document
    Annotation annotation = 
        new Annotation("Usaine Bolt may play football trial in Australia. China's economic growth cools amid trade tensions. Trump is under fire after Putin meeting.");
    pipeline.annotate(annotation);

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

当我运行代码时,没有显示错误或警告消息,只有从示例文档形成的关系元组。预期的输出将是由我包含的文件列表形成的元组的混响格式的 TSV。如何使添加的属性起作用?感谢您提供任何帮助和/或见解!

【问题讨论】:

    标签: java eclipse stanford-nlp


    【解决方案1】:

    使用独立 OpenIE 系统的说明在这里:

    https://nlp.stanford.edu/software/openie.html

    当使用 OpenIE 作为管道中的注释器时,这些选项不起作用,它们在使用 OpenIE 的 main() 方法时起作用。

    示例命令位于上面的链接中。

    java -mx1g -cp "*" edu.stanford.nlp.naturalli.OpenIE  /path/to/file1  /path/to/file2
    

    在 Java 代码中你应该直接调用 OpenIE 的 main() 方法。

    【讨论】:

    • 我明白了,谢谢!这些选项绝对可以在命令行中使用。这并不完全相关,但是当使用管道中的某些其他注释器(例如 PaserAnnotator,而不是 OpenIE)时,这些选项是否有效?
    • OpenIE 注释器就是这样实现的。虽然我应该在管道中添加一些没有意义的东西。例如,“filelist”没有意义……你为整个管道指定一个文件列表来运行,所以只为一个注释器设置一个单独的选项是没有意义的。
    • 真的,这两个选项在管道中都没有意义。如果您正在注释文本,则输出格式不会做任何事情,因为它实际上并没有输出任何内容。如果你想写一个混响格式的RelationTriple(例如,你代码中的println),你可以使用RelationTriple#toReverbString()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    相关资源
    最近更新 更多