繁体   English   中英

无法为Stanford CoreNLP的OpenIE注释器实现选项

[英]Can't implement options for Stanford CoreNLP's OpenIE annotator

我已经在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());
      }
    }
  }
}

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

以下是使用独立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()方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM