我是pycharm professional ide,python和nltk的新手。 我想使用stanfordNertagger进行项目工作。当我在pycharm professional
中的python文件中使用以下代码时from nltk.tag import StanfordNERTagger
from nltk.tokenize import word_tokenize
stanford_classifier = '/home/PycharmProjects/Stanford-NER-Python/stanford/stanford-ner-2015-12-09/classifiers\english.all.3class.distsim.crf.ser.gz'
stanford_ner_path = '/home/PycharmProjects/Stanford-NER-Python/stanford/stanford-ner-2015-12-09/stanford-ner.jar'
# Creating Tagger Object
st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')
text = 'While in France, Christine Lagarde discussed short-term stimulus efforts in a recent interview with the Wall Street Journal.'
tokenized_text = word_tokenize(text)
classified_text = st.tag(tokenized_text)
print classified_text
显示的错误是
Traceback (most recent call last):
File "/home/premchikkus/PycharmProjects/Stanford-NER-Python/main.py", line 9, in <module>
st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')
File "/home/premchikkus/PycharmProjects/Stanford-NER-Python/venv/local/lib/python2.7/site-packages/nltk/tag/stanford.py", line 168, in __init__
super(StanfordNERTagger, self).__init__(*args, **kwargs)
File "/home/premchikkus/PycharmProjects/Stanford-NER-Python/venv/local/lib/python2.7/site-packages/nltk/tag/stanford.py", line 53, in __init__
verbose=verbose)
File "/home/premchikkus/PycharmProjects/Stanford-NER-Python/venv/local/lib/python2.7/site-packages/nltk/internals.py", line 719, in find_jar
searchpath, url, verbose, is_regex))
File "/home/premchikkus/PycharmProjects/Stanford-NER-Python/venv/local/lib/python2.7/site-packages/nltk/internals.py", line 635, in find_jar_iter
(name_pattern, path_to_jar))
LookupError: Could not find stanford-ner.jar jar file at /home/PycharmProjects/Stanford-NER-Python/stanford/stanford-ner-2015-12-09/stanford-ner.jar
我已经在pycharm ide中设置了环境变量 CLASSPATH = /home/PycharmProjects/Stanford-NER-Python/stanford/stanford-ner-2015-12-09/classifiers\english.all.3class.distsim.crf.ser.gz;/home/PycharmProjects/Stanford-NER-蟒/斯坦福/斯坦福-NER-2015年12月9日/斯坦福-ner.jar
我正在使用nltk版本3.2.1
python 2.7
ubuntu 16.04
提前致谢。
答案 0 :(得分:0)
没关系。我知道了。 stanford_classifier和stanford_ner_path的位置是错误的,需要在StandfordNERTagger()中传递前两个参数,不需要ascii。