26

在从斯坦福 CoreNLP 网站构建示例应用程序时,我遇到了一个奇怪的异常:

Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:493)
…
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
…

这只发生在属性pos及其之后的属性包含在属性中时。

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

这是我的 pom.xml 的依赖项:

<dependencies>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
    <scope>compile</scope>
</dependency>
</dependencies>
4

3 回答 3

54

我实际上在 Stackoverflow 上另一个问题的问题描述中找到了答案。

引用 WP McNeill 的话

Maven 不会自动下载模型文件,但前提是您将模型行添加到 .pom。这是一个获取代码和模型的 .pom 片段。

这是我的依赖项现在的样子:

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

<classifier>models</classifier>需要注意的重要部分是底部的条目。为了让 Eclipse 维护这两个引用,您需要为每个stanford-corenlp-3.2.0和配置一个依赖项stanford-corenlp-3.2.0-models

于 2013-08-28T15:48:17.740 回答
2

如果您需要将模型用于其他语言(如中文、西班牙语或阿拉伯语),您可以将以下部分添加到pom.xml文件中(分别替换models-chinesemodels-spanishmodels-arabic用于这两种语言):

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.8.0</version>
    <classifier>models-chinese</classifier>
</dependency>
于 2017-08-14T03:03:21.987 回答
1

Gradle 显然可以使用:

implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2'
implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2:models'

或者如果您使用 compile (depreated):

compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.2'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.2' classifier: 'models'
于 2020-06-25T20:54:15.433 回答