【发布时间】:2016-10-10 10:24:57
【问题描述】:
我正在尝试使用 Stanford CoreNLP 测试 OpenIE http://nlp.stanford.edu/software/openie.html
我正在使用基于http://stanfordnlp.github.io/CoreNLP/openie.html 上提供的演示之一的以下代码
public static void main(String[] args) throws Exception {
// Create the Stanford CoreNLP pipeline
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
props.setProperty("openie.triple.strict", "false");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate an example document.
//File inputFile = new File("src/test/resources/0.txt");
//String text = Files.toString(inputFile, Charset.forName("UTF-8"));
String text = "Cats do not drink milk.";
Annotation doc = new Annotation(text);
pipeline.annotate(doc);
// Loop over sentences in the document
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
// 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" +
triple.subjectLemmaGloss() + "|\t" +
triple.relationLemmaGloss() + "|\t" +
triple.objectLemmaGloss());
}
}
}
这违反直觉导致三元组
1.0| cat| drink| milk
被提取,这与我使用输入文本“猫喝牛奶”得到的结果相同。如果我将“openie.triple.strict”设置为“true”,则根本不会提取三元组。有没有办法像猫一样提取三元组?不喝酒 |牛奶?
【问题讨论】:
-
我收到 Java 堆大小错误的确切代码!你有过这样的问题吗?
标签: stanford-nlp information-extraction