Reputation: 1
this is my first time here posting something; so if I have demonstrated any bad practice- please tell.
So currently I am trying to use OpenIE from Stanford to extract information from web-mined data. As I am really new to Java, I just copied the example code snippet from their page: http://nlp.stanford.edu/software/openie.shtml
Which looks like this:
import java.util.*;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.naturalli.NaturalLogicAnnotations;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ie.util.RelationTriple;
import edu.stanford.nlp.util.CoreMap;
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,depparse,natlog,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation doc = new Annotation("Obama was born in Hawaii. He is our president.");
pipeline.annotate(doc);
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
for (RelationTriple triple : triples) {
System.out.println(triple.confidence + "\t" +
triple.subjectLemmaGloss() + "\t" +
triple.relationLemmaGloss() + "\t" +
triple.objectLemmaGloss());
}
}
}
Then I compiled it into a class and put it into the openIE jar from their site.
I ran such a command, which is nearly identical to their command-line invocation example:
java -mx1g -cp stanford-openie.jar:stanford-openie-models.jar Example
But in the end I got such an error:
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz" as either class path, filename or URL
While their command line invocation would work as shown on their page, I think this is a problem with my Java skills. However I couldn't figure out how to fix this, nor the relevant questions asked on Stackoverflow would help. Why cannot it resolve the classpath?
Note: I saw somebody posting about having CoreNLP in their workspace at the same time, but I am sure I am NOT putting those JARs together under the same directory.
Upvotes: 0
Views: 1124
Reputation: 1468
Change the setProperty line to the following. I was facing the same issue. A change in this line made it work.
Also, you should include the CoreNLP and the Openie jars in the path to help it work properly.
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
Upvotes: 2