Richard
Richard

Reputation: 159

Stanford CoreNLP: Building Error (NoSuchMethodError)

Sorry if this is a newbie's question. I was trying to use maven in Netbeans to build CoreNLP parser.

I first added dependency of stanford-corenlp 1.2.0. However, I always got an error while compiling my code. I tried to simplify my code to just create the StanfordCoreNLP object, but it still did not function with the same error message. I guess here might come with the main trouble spot then.

My simplified code shows as:

import java.util.Properties;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;

Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

The error message:

Exception in thread "main" java.lang.NoSuchMethodError: 
edu.stanford.nlp.process.PTBTokenizer.factory
(Ledu/stanford/nlp/process/LexedTokenFactory;Ljava/lang/String;)Ledu/stanford/nlp/objectbank/TokenizerFactory;
        at edu.stanford.nlp.pipeline.PTBTokenizerAnnotator.<init>(PTBTokenizerAnnotator.java:42)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP$1.create(StanfordCoreNLP.java:365)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP$1.create(StanfordCoreNLP.java:355)
        at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:62)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:328)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:194)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:184)
        at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:176)
        at com.mycompany.hellocore.App.main(App.java:26)

I also tried the same thing via maven on Eclipse, the error message is still the same. Can anyone give me some suggestions? Thanks!

OS: Mac Lion / Java version: 1.6.0_29


[Update] 01-6-2012 Based on Sri Sankaran's suggestion, i tried mvn dependency: tree:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hellocore 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ hellocore ---
[INFO] com.mycompany:hellocore:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:1.2.0:compile
[INFO]    +- xom:xom:jar:1.2.5:compile
[INFO]    |  +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO]    |  +- xerces:xercesImpl:jar:2.8.0:compile
[INFO]    |  \- xalan:xalan:jar:2.7.0:compile
[INFO]    \- joda-time:joda-time:jar:2.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.483s
[INFO] Finished at: Fri Jan 06 08:55:06 EST 2012
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------

The setting in my Netbeans:

enter image description here

But it seems like the library in need looks the same as what is already downloaded in Netbeans. The project still stops while Adding annotator tokenize.


[Update] 01-09-2012

After i reinstalled my system, the problem was gone. So i think the code and the module are both correct. The classpath directories might be just messed up by me. Thank you for all people's helps.

Just a gentle reminder for people using corenlp via Netbeans. In addition to the standard dependency of stanford-corenlp.jar. If you want to inlcude the stanford-corenlp-models.jar into your project. Seems like you also need to specify the <classifier> to add the models to the dependency repository.

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

Upvotes: 2

Views: 2722

Answers (2)

Khairul
Khairul

Reputation: 1483

You need to include model (POS tag, NER, Coref, etc), so your annotator worked.
You can get it here

enter image description here

Upvotes: 1

Sri Sankaran
Sri Sankaran

Reputation: 8310

The usage of Standford NLP suggests that there are other dependencies. If they aren't transitively included in the classpath by virtue of the stated dependency on stanford-corenlp 1.2.0 you will have to explicitly state these other dependencies as well. The command mvn dependency:tree should display your effective dependency tree.

Upvotes: 0

Related Questions