Search code examples
javastanford-nlp

Stanford NLP sentiment running error


I downloaded Stanford NLP 3.5.2 at http://nlp.stanford.edu/software/stanford-corenlp-full-2015-04-20.zip

Then I unzip the file and move to the new unzip directory.

I ran as instructed at:

http://nlp.stanford.edu/sentiment/code.html

java edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz test.txt

Then I have an error:

"Error: Could not find or load main class edu.stanford.nlp.sentiment.Evaluate"

Followed with some instructions in stackoverflow, I used:

java -cp "*" edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz test.txt

Then I have another problem:

Exception in thread "main" java.lang.NullPointerException
    at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:461)
    at edu.stanford.nlp.io.IOUtils.readObjectFromURLOrClasspathOrFileSystem(IOUtils.java:313)
    at edu.stanford.nlp.sentiment.SentimentModel.loadSerialized(SentimentModel.java:627)
    at edu.stanford.nlp.sentiment.Evaluate.main(Evaluate.java:72)

How should I fix the problem? (I am using Java 8 1.8.0_25 on Mac)


Solution

  • The documentation is not up to date. The javadoc says that you have to add -model and -treebank before the corresponding files:

    java -cp "*" edu.stanford.nlp.sentiment.Evaluate -model edu/stanford/nlp/models/sentiment/sentiment.ser.gz -treebank test.txt