Error using StanfordCoreNLP

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; /** * 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 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!

+5
source share
4 answers

The tag file must be placed in the root directory of the project.

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

Tested in the Eclipse project.

+3
source

I had the same problem. Fixed using:

 <dependencies> <dependency> <groupId>edu.stanford.nlp</groupId> <artifactId>stanford-corenlp</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>edu.stanford.nlp</groupId> <artifactId>stanford-corenlp</artifactId> <version>3.5.2</version> <classifier>models</classifier> </dependency> </dependencies> 

or for SBT:

 "edu.stanford.nlp" % "stanford-corenlp" % "3.5.2", "edu.stanford.nlp" % "stanford-corenlp" % "3.5.2" classifier "models", 
+6
source

The problem may be that you start the server through a jar file that you must create from a compiled classified one, so make sure to re-create the jar after installing the required -english-left3words-distsim.tagger file in the folder location that can be seen on error console. After you recreate the jar, start the server.

0
source

I encountered the same error and took me a long time to figure it out. Essentially, there are two main jar files that we will need to solve. One of them is the stable version 3.6.0 and the current version 3.7.0

So, download both jar files from the following link and link . Now extract both jar files. There is currently no sample folder in the extracted flag file folder 3.7.0. You can find this folder in the extracted folder with the 3.0 file.

Copy this folder from version 3.6 to version 3.7.

Now from the root folder, run the following command:

 java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000 

It should work fine. To use the server, follow these steps py-corenlp

0
source

All Articles