2013-02-06 59 views
2

我正在使用IKVM.NET的StandordCoreNLP。是否有指定解析器的车型为StanfordCoreNLP指定模型路径

var pipeLine = new StanfordCoreNLP(props); 

路径的方式抛出一个异常:

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 

回答

2

我不知道您是否可以从IKVM.NET一个jar文件访问资源,但您当然可以解压缩jar文件以获取常规操作系统文件(jar -xf models.jar)并将模型加载为文件。要么需要镜像jar文件的目录结构(使用类似上面例子的路径,并使用相对路径),要么需要为props文件中的所有模型设置属性,以提供它们可以通过的文件路径找到。请参阅pos.model,ner.model,parse.model等。

4

这将有助于了解如何定义属性。如果您使用默认属性,则可能只是在类路径中缺少models.jar(如版本3.2中的this one)。下载并确保它被加载。

如果以某种其他方式配置属性,则可能在字符串中导致IO错误的语法错误。下面是我的加载不同的pos.model自定义属性的样子:

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

重要的是要注意,在路径没有前导斜杠/是很重要的。

如果这样做没有帮助,请查看Galal Aly's tutorial,其中标记器从模型文件中提取并单独加载。

0

我有同样的问题。在我的情况下,我没有使用完整的.jar文件,而是提取了.tagger文件。我只是说做手工添加后的模型对象的属性是这样的:

Properties props = new Properties(); 

**props.put("pos.model", "E:\\Documents\\Dependencies\\english-left3words-distsim.tagger");** 
3

这是完整的属性,如果你不包括在类路径中models.jar。

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");