【发布时间】:2016-04-19 02:39:24
【问题描述】:
我不明白如何从我的 java 应用程序加载 CoreNLP 的 Shift-Reduce Constituency Parser (SRCP)。
我正在使用 Apache Maven 来管理我的项目的依赖项。根据文档,SRCP 模型未与 CoreNLP 捆绑,因此我已单独下载 stanford-srparser-2014-10-23-models.jar (http://nlp.stanford.edu/software/srparser.shtml) 并将该文件放入:
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-srparser-2014-10-23-models.jar
就是和核心依赖jar在同一个目录
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-corenlp-3.5.2.jar
这是我项目的 pom.xml 的相关部分:
<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>
编译成功:
mvn clean compile
但是当我尝试加载应用程序时,我收到:
java.lang.reflect.InvocationTargetException
...
Caused by: edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/srparser/englishSR.ser.gz" as either class path, filename or URL
我解压编译好的项目war,“edu/stanford/nlp/models/srparser/englishSR.ser.gz”不存在。
这是我在应用中调用模型的方式:
// Initialize a CoreNLP pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;
// Set the CoreNLP pipeline annotators.
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
如何更新我的 Maven 配置以强制我的 CoreNLP 依赖项包含 srparser 模型?请记住,我需要此配置才能在其他开发人员的环境中运行,因此如果可能,该解决方案应该是干净且可重复使用的。
谢谢!
编辑:
针对@jah 的评论,下面是mvn dependency:tree 的结果。构建成功,但 srparser 模型未编译/存在:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ [REDACTED] ---
Downloading:
...
[INFO] com.[REDACTED].nlp:nlp:war:0.1.0
[INFO] +- com.strategicgains:RestExpress:jar:0.11.2:compile
[INFO] | +- com.strategicgains:RestExpress-Common:jar:0.11.2:compile
[INFO] | +- com.strategicgains:DateAdapterJ:jar:1.1.4:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- io.netty:netty-all:jar:4.0.29.Final:compile
[INFO] | +- org.owasp.encoder:encoder:jar:1.1.1:compile
[INFO] | \- com.jcraft:jzlib:jar:1.1.3:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:3.5.2: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] | \- javax.json:javax.json-api:jar:1.0:compile
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:models:3.5.2:compile
[INFO] +- org.json:json:jar:20151123:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.6.4:compile
[INFO] \- commons-io:commons-io:jar:1.3.2:compile
【问题讨论】:
-
当你
mvn dependency:tree时会发生什么? -
有趣的是,maven central 中的该库的这个版本具有非常不同的内容(主要是文本文件)
-
@jah 我用
mvn dependency:tree的结果编辑了我的帖子。 srparser 依赖项不存在。 -
存在依赖,它是从底部算起的第 6 行。我猜这个罐子也包含在你的战争中。我认为
edu/stanford/nlp/models/srparser/englishSR.ser.gz也包括在内,通过那个罐子。 -
@jah 倒数第6行实际上是指默认的corenlp模型jar,不包括srparser模型。
标签: java maven stanford-nlp