2013-02-06 57 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");