Reputation: 43
I've tried using both the core library and the simple wrapper around it and both fail to find triples for the same trivial sentences.
The simple wrapper code:
for (final Quadruple<String, String, String, Double> tripple : sentence.openie()) {
System.out.println(tripple);
}
and the core library's code is their own example usage:
package edu.stanford.nlp.naturalli;
import edu.stanford.nlp.ie.util.RelationTriple;
import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.PropertiesUtils;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
/**
* A demo illustrating how to call the OpenIE system programmatically.
*/
public class OpenIEDemo {
private OpenIEDemo() {} // static main
public static void main(String[] args) throws Exception {
// Create the Stanford CoreNLP pipeline
Properties props = PropertiesUtils.asProperties(
"annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie"
// , "depparse.model", "edu/stanford/nlp/models/parser/nndep/english_SD.gz"
// "annotators", "tokenize,ssplit,pos,lemma,parse,natlog,openie"
// , "parse.originalDependencies", "true"
);
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate an example document.
String text;
if (args.length > 0) {
text = IOUtils.slurpFile(args[0]);
} else {
text = "Obama was born in Hawaii. He is our president.";
}
Annotation doc = new Annotation(text);
pipeline.annotate(doc);
// Loop over sentences in the document
int sentNo = 0;
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
System.out.println("Sentence #" + ++sentNo + ": " + sentence.get(CoreAnnotations.TextAnnotation.class));
// Print SemanticGraph
System.out.println(sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class).toString(SemanticGraph.OutputFormat.LIST));
// 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());
}
// Alternately, to only run e.g., the clause splitter:
List<SentenceFragment> clauses = new OpenIE(props).clausesInSentence(sentence);
for (SentenceFragment clause : clauses) {
System.out.println(clause.parseTree.toString(SemanticGraph.OutputFormat.LIST));
}
System.out.println();
}
}
}
Both methods find triples pass and fail the same tests:
The cat jumped over the fence.: (cat,jumped over,fence,1.0)
The brown dog barked.: FAIL
The apple was eaten by John.: (apple,was eaten by,John,1.0)
Joe ate the ripe apple.: (Joe,ate,ripe apple,1.0)
They named their daughter Natasha.: (They,named,their daughter Natasha,1.0)
Bob sold me her boat.: FAIL
Grandfather left Rosalita and Raoul all his money.: FAIL
Who killed the cat?: FAIL
How many astronauts have walked on the moon?: (astronauts,have walked on,moon,1.0)
When it fails the collection it returns is empty.
Has anyone had similar problems and a workaround or any alternative solutions?
Upvotes: 1
Views: 992
Reputation: 1563
OpenIE only returns triples, so you would have to add your own rules if you also wanted to extract sentences without objects or other verbal complements. The same is true for questions; OpenIE is intended for large-scale relation extraction from text such as Wikipedia and in this context it doesn't make sense to consider questions.
Regarding the Bob example, it seems that this is only working in the version that is up on GitHub, so you'd either have to clone this and compile it yourself or wait until the next release to get this sentence to work.
Upvotes: 1