问题描述
我正在使用corenlp 3.3.1构建基于Maven的Java应用程序.
I'm building a maven-based java application using corenlp 3.3.1.
主要的pom.xml依赖项是
The salient pom.xml dependencies are
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.3.1</version>
<classifier>models</classifier>
</dependency>
运行
mvn dependency:tree
给予:
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:3.3.1:compile
[INFO] | +- com.io7m.xom:xom:jar:1.2.10: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.1:compile
[INFO] | +- de.jollyday:jollyday:jar:0.4.7:compile
[INFO] | | \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] | \- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:models:3.3.1:compile
我的代码包括:
Properties props = new Properties();
props.put("annotators",
"tokenize, ssplit, pos, lemma, ner, parse, dcoref");
this.pipeline = new StanfordCoreNLP(props);
到达这一点后,这将引发异常:
This throws an exception after getting this far:
Adding annotator tokenize
Adding annotator ssplit
Adding annotator pos
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.2 sec].
Adding annotator lemma
Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [4.8 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... done [2.3 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz ... done [3.8 sec].
例外是
java.lang.NoSuchMethodError: org.joda.time.Duration.compareTo(Lorg/joda/time/ReadableDuration;)I
at edu.stanford.nlp.time.SUTime$Duration.compareTo(SUTime.java:3671)
at edu.stanford.nlp.time.SUTime$Duration.max(SUTime.java:3753)
at edu.stanford.nlp.time.SUTime$Time.difference(SUTime.java:1434)
at edu.stanford.nlp.time.SUTime$Range.<init>(SUTime.java:4072)
at edu.stanford.nlp.time.SUTime.<clinit>(SUTime.java:655)
at edu.stanford.nlp.time.EnglishTimeExpressionPatterns.initTimeUnitsMap(EnglishTimeExpressionPatterns.java:1542)
at edu.stanford.nlp.time.EnglishTimeExpressionPatterns.<init>(EnglishTimeExpressionPatterns.java:47)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.init(TimeExpressionExtractorImpl.java:65)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.<init>(TimeExpressionExtractorImpl.java:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at edu.stanford.nlp.time.TimeExpressionExtractorFactory.create(TimeExpressionExtractorFactory.java:45)
at edu.stanford.nlp.time.TimeExpressionExtractorFactory.createExtractor(TimeExpressionExtractorFactory.java:28)
at edu.stanford.nlp.ie.regexp.NumberSequenceClassifier.<init>(NumberSequenceClassifier.java:79)
at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:67)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$6.create(StanfordCoreNLP.java:619)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:81)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:260)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:127)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:123)
at com.othermaps.analysis.madhatter.service.ServiceImpl.initTAEngines(ServiceImpl.java:49)
... 34 more
我假设这是错误版本的JodaTime"问题-但是,如果我从corenlp的依赖项中明确排除了JodaTime工件,则找不到不会产生此异常的版本:
I'm assuming that this is a 'wrong version of JodaTime' issue -- however I can't find a version which doesn't generate this Exception, if I explicitly exclude the JodaTime artifact from the dependencies of corenlp:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.3.1</version>
<exclusions>
<exclusion>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</exclusion>
</exclusions>
</dependency>
并手动添加明确定义的版本
and add an explicit-defined version manually
例如
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
(是的,我知道与自动添加的依赖项的版本相同:这只是我尝试过的过程的一个示例;-)
(Yes I know that's the same version as the automatically-added dependency: this is just an example of the process I've tried ;-)
感谢所有帮助.
D
推荐答案
我最后的评论包含答案-这与CXF捆绑包中包含的Joda jar冲突.
My last comment contains the answer -- it was a conflict with a Joda jar included in a CXF bundle.
这篇关于Maven构建在运行时引发JodaTime异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!