user3928256 user3928256 - 1 year ago 97
Java Question

Error when using StanfordCoreNLP

I'm trying to use Stanford CoreNLP as a library in my java program. I use IntelliJ as the IDE.
I was trying to test the library, so I wrote this code:

import edu.stanford.nlp.pipeline.StanfordCoreNLP;

import java.util.Properties;

* Created by Benjamin on 15/5/4.
public class SentimentAnaTest {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

and it shows the error like this:

Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(
at edu.stanford.nlp.pipeline.AnnotatorPool.get(
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(
at SentimentAnaTest.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(
Caused by: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(
... 10 more
Caused by: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(
... 16 more

I read a solution here but couldn't figure out what the problem was, because I added the library from the Maven Central Repository which already included the "stanford-corenlp-3.5.2-models.jar".

From the error message it seemed like the program was trying to load a file from
so I download the tagger file from here and put it into
. However it still didn't work.

Can someone tell me whats this error is about and help me to solve it? Thank you!

Answer Source

The tagger file has to be placed into your project root.

-- src --> SentimentAnaTest
-- english-left3words/english-left3words-distsim.tagger

Tested in Eclipse project.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download