无法在OS X上实例化StanfordNERTagger

时间:2016-08-07 23:05:19

标签: python nltk osx-yosemite stanford-nlp pos-tagger

我正在尝试实例化 StanfordNERTagger 。这就是我想要的:

st = StanfordNERTagger("/Users/attitude/Desktop/english.all.3class.caseless.distsim.crf.ser.gz","/Users/attitude/Desktop/stanford-ner-2015-12-09/stanford-ner.jar")

我已将CLASSPATH变量设置为/Users/attitude/Desktop/stanford-ner-2015-12-09/stanford-ner.jar(我还尝试将父文件夹作为值 - /Users/attitude/Desktop/stanford-ner-2015-12-09)。

但是,我收到此错误:

LookupError: Could not find stanford-ner.jar jar file at /Users/attitude/Desktop/stanford-ner-2015-12-09/stanford-ner.jar

我完成了这两个答案中提到的所有内容 - thisthis。我现在还要做些什么来解决这个错误?

OS X Yosemite - Python 2.7。

1 个答案:

答案 0 :(得分:2)

<强> TL; DR

如果不设置环境变量,请使用关键字参数model_filenamepath_to_jar

from nltk.tag import StanfordNERTagger

stanford_ner_dir = '/home/alvas/stanford-ner/'
eng_model_filename= stanford_ner_dir + 'classifiers/english.all.3class.distsim.crf.ser.gz'
my_path_to_jar= stanford_ner_dir + 'stanford-ner.jar'

st = StanfordNERTagger(model_filename=eng_model_filename, path_to_jar=my_path_to_jar) 
st.tag('Rami Eid is studying at Stony Brook University in NY'.split())

长期:

请参阅https://stackoverflow.com/a/34112695/610569