对不起,如果这是一个新手的问题。 我试图在Netbeans中使用maven来构建CoreNLP解析器。Stanford CoreNLP:构建错误(NoSuchMethodError)
我首先添加了stanford-corenlp 1.2.0的依赖项。但是,编译我的代码时总是出错。我试图简化我的代码来创建StanfordCoreNLP对象,但它仍然不能用相同的错误消息运行。我想这里可能会出现主要的麻烦点。
我的简化代码显示为:
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);
错误消息:
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)
我也通过行家试过基于Eclipse同样的事情,错误消息仍然是相同的。任何人都可以给我一些建议吗?谢谢!
操作系统:Mac狮子/ Java版本:1.6.0_29
[更新] 2012年1月6日根据斯里兰卡桑卡兰的建议,我想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] ------------------------------------------------------------------------
的在我的Netbeans中设置:
但似乎需要的库看起来与已经在Netbeans中下载的库相同。该项目仍然停止,而Adding annotator tokenize
。
[更新] 2012年1月9日
后我重新安装我的系统,问题就消失了。所以我认为代码和模块都是正确的。 classpath目录可能会被我搞乱。感谢所有人的帮助。
只是通过Netbeans使用corenlp的人提示。除了stanford-corenlp.jar的标准依赖关系之外。如果你想将stanford-corenlp-models.jar包含到你的项目中。看起来像你还需要指定<classifier>
将模型添加到依赖库。
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>1.2.0</version>
<classifier>models</classifier>
</dependency>
您好,感谢您的快速回复。我尝试了'mvn dependency:tree'。但是,似乎应该下载基本的东西(如我的文章中所述)。但同样,它仍然无法构建标记器,因为项目在“添加注释器标记化”处停止。 – Richard 2012-01-06 14:12:40