Maven未能下载CoreNLP模型

Jon*_*est 26 stanford-nlp maven

当从Stanford 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
…
Run Code Online (Sandbox Code Playgroud)

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

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

这是我的pom.xml的依赖:

<dependencies>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
    <scope>compile</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

Jon*_*est 51

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

引用WP麦克尼尔:

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>
Run Code Online (Sandbox Code Playgroud)

需要注意的重要部分是<classifier>models</classifier>底部的条目.为了让Eclipse来维持两个引用,你需要配置每个依赖stanford-corenlp-3.2.0stanford-corenlp-3.2.0-models.

  • 如果您使用SBT,可以将以下行添加到库依赖项序列:"edu.stanford.nlp"%"stanford-corenlp"%"3.2.0","edu.stanford.nlp"%"stanford- corenlp"%"3.2.0"分类器"模型" (11认同)
  • @eliasah:我正在做你在评论中所说的相同的事情,但它没有下载模型!它已经2小时仍然没有下载任何与模型相关的东西! (2认同)