3

I am using StandordCoreNLP using IKVM.NET. Is there a way to specify a path to the parser's models

   var pipeLine = new StanfordCoreNLP(props);

throws an exception:

java.lang.RuntimeException: 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
demongolem
  • 9,474
  • 36
  • 90
  • 105
AstroSharp
  • 1,872
  • 2
  • 22
  • 31

4 Answers4

8

This is the full set of properties if you are not including the models.jar in the class path.

Properties props = new Properties();
String modPath = "<YOUR PATH TO MODELS>/models3.4/edu/stanford/nlp/models/";
props.put("pos.model", modPath + "pos-tagger/english-left3words/english-left3words-distsim.tagger");
props.put("ner.model", modPath + "ner/english.all.3class.distsim.crf.ser.gz");
props.put("parse.model", modPath + "lexparser/englishPCFG.ser.gz");
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.put("sutime.binders","0");
props.put("sutime.rules", modPath + "sutime/defs.sutime.txt, " + modPath + "sutime/english.sutime.txt");
props.put("dcoref.demonym", modPath + "dcoref/demonyms.txt");
props.put("dcoref.states", modPath + "dcoref/state-abbreviations.txt");
props.put("dcoref.animate", modPath + "dcoref/animate.unigrams.txt");
props.put("dcoref.inanimate", modPath + "dcoref/inanimate.unigrams.txt");
props.put("dcoref.big.gender.number", modPath + "dcoref/gender.data.gz");
props.put("dcoref.countries", modPath + "dcoref/countries");
props.put("dcoref.states.provinces", modPath + "dcoref/statesandprovinces");
props.put("dcoref.singleton.model", modPath + "dcoref/singleton.predictor.ser");
Vijay Raj
  • 146
  • 1
  • 4
6

It would have been helpful to see how you defined your properties. If you used default properties, you're probably just missing the models.jar (like this one for version 3.2) in your classpath. Download it and make sure that it gets loaded.

If you configure the properties some other way, you may have syntax errors in the string that result in IO errors. Here's what my custom properties for loading a different pos.model look like:

Properties props = new Properties();
// using wsj-bidirectional model
props.put("pos.model", "edu/stanford/nlp/models/pos-tagger/wsj-bidirectional/wsj-0-18-bidirectional-distsim.tagger");
// using standard pipeline
props.put("annotators", "tokenize, ssplit, pos, lemma, parse");
// create pipeline
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

It's important to note that there is no leading slash / in the path.

If that doesn't help, please have a look at Galal Aly's tutorial where the tagger is extracted from the models file and loaded separately.

Jonny
  • 1,453
  • 16
  • 25
2

I don't know whether you can access resources from a jar file with IKVM.NET, but you could certainly unpack the jar file to get regular operating system files (jar -xf models.jar) and load the models as files. Either you need to mirror the directory structure of the jar file (with paths like the example above, and using relative paths), or you need to set properties for all the models in the props file to give the file paths by which they can be found. See pos.model, ner.model, parse.model, etc.

Christopher Manning
  • 9,360
  • 34
  • 46
1

I had the same issue. In my case, i weren't using the complete .jar file, instead i had the .tagger file extracted. i just added manually added the model after making the properties object like this :

Properties props = new Properties();

**props.put("pos.model", "E:\\Documents\\Dependencies\\english-left3words-distsim.tagger");**
Faisal
  • 566
  • 5
  • 17