I am trying to use Stanford CoreNLP as a library in my java program. I am using IntelliJ as an IDE. I tried to check the library, so I wrote this code:
import edu.stanford.nlp.pipeline.StanfordCoreNLP; import java.util.Properties; 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 this error:
Adding annotator tokenize TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer. Adding annotator ssplit Adding annotator pos Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:292) at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85) at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289) at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126) at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122) at SentimentAnaTest.main(SentimentAnaTest.java:12) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:770) at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:298) at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:263) at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97) at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77) at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:59) at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:290) ... 10 more Caused by: java.io.IOException: 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.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:481) at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765) ... 16 more
I read the solution here , but couldn't figure out what the problem was because I added the library from the Maven Central repository, which already included "stanford-corenlp-3.5.2-models.jar".
From the error message, it seemed that the program was trying to download the file from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger , so I download the tagger file from here and put it in /edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger . However, this still did not work.
Can someone tell me what this error is and help me solve this problem? Thanks!
source share