【发布时间】: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