I am trying to test OpenIE with Stanford CoreNLP http://nlp.stanford.edu/software/openie.html
I am using the following code based on one of the demos available on 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());
}
}
}
This counter-intuitively results in the triple
1.0| cat| drink| milk
being extracted, which is the same result I get using input text "Cats drink milk." If I set "openie.triple.strict" to "true" no triples are extracted at all. Is there a way to extract a triple like cats | do not drink | milk ?
I think you want to set "openie.triple.strict" to true to ensure logically warranted triples. OpenIE does not extract negative relations, it is only designed to find positive ones.
So you are getting the correct behavior when "openie.triple.strict" is set to true (i.e. no relation being extracted). Note that a relation is extracted for "Cats drink milk." when "openie.triple.strict" is set to true.