Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven fails to download CoreNLP models

When building the sample application from the Stanford CoreNLP website, I ran into a curious exception:

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
…

This only happened when the property pos and the ones after it were included in the properties.

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

Here is the dependency from my pom.xml:

<dependencies>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
    <scope>compile</scope>
</dependency>
</dependencies>
like image 317
Jonny Avatar asked Aug 28 '13 15:08

Jonny


3 Answers

I actually found the answer to that in the problem description of another question on Stackoverflow.

Quoting W.P. McNeill:

Maven does not download the model files automatically, but only if you add models line to the .pom. Here is a .pom snippet that fetches both the code and the models.

Here's what my dependencies look like now:

<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>

The important part to note is the entry <classifier>models</classifier> at the bottom. In order for Eclipse to maintain both references, you'll need to configure a dependency for each stanford-corenlp-3.2.0 and stanford-corenlp-3.2.0-models.

like image 185
Jonny Avatar answered Nov 03 '22 01:11

Jonny


In case you need to use the models for other languages (like Chinese, Spanish, or Arabic) you can add the following piece to your pom.xml file (replace models-chinese with models-spanish or models-arabic for these two languages, respectively):

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.8.0</version>
    <classifier>models-chinese</classifier>
</dependency>
like image 43
Pedram Avatar answered Nov 03 '22 01:11

Pedram


With Gradle apparently you can use:

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

or if you use compile (depricated):

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'
like image 1
gneusch Avatar answered Nov 03 '22 00:11

gneusch