在NLTK Python中使用Stanford POS Tagger时出错 [英] Error using Stanford POS Tagger in NLTK Python
问题描述
我正在NLTK中尝试使用Stanford POS Tagger,但无法运行此处给出的示例代码
I am trying to use Stanford POS Tagger in NLTK but I am not able to run the example code given here http://www.nltk.org/api/nltk.tag.html#module-nltk.tag.stanford
import nltk
from nltk.tag.stanford import POSTagger
st = POSTagger(r'english-bidirectional-distim.tagger',r'D:/stanford-postagger/stanford-postagger.jar')
st.tag('What is the airspeed of an unladen swallow?'.split())
我已经将环境变量添加为
I have already added environment variables as
CLASSPATH = D:/stanford-postagger/stanford-postagger.jar
STANFORD_MODELS = D:/stanford-postagger/models/
这是我不断收到的错误
回溯(最近通话最近一次):
Traceback (most recent call last):
File "D:\pos_stanford.py", line 4, in <module>
st = POSTagger(r'english-bidirectional-distim.tagger',
r'D:/stanford-postagger/stanford-postagger.jar')
... LookupError: NLTK was unable to find the english-bidirectional-distim.tagger file! Use software specific configuration paramaters or set the STANFORD_MODELS environment variable.
一些论坛建议
File "C:\Python27\lib\site-packages\nltk\tag\stanford.py", line 45, in __init__
env_vars=('STANFORD_MODELS'), verbose=verbose)
应进行更改,以使
env_vars=('STANFORD_MODELS',), verbose=verbose)
但是它也不能解决问题. 请帮助我解决这个问题.
but it doesn't solve the problem either. Please Help me in solving this issue.
其他信息: 我在用 Windows 7 64位 Python 2.7 32位 NLTK 2.0
Other Information: I am using Windows 7 64 bit Python 2.7 32 bit NLTK 2.0
推荐答案
注意:只需将其发布为答案,以防将来其他人遇到此问题
Note : Just posting it as answer to help in case others face this issue in future
我终于发现我做错了..结果真是个大错.
I finally found out what I did wrong.. it turned out to be a blunder.
Tagger文件名不是'english-bidirectional-distim.tagger' 而是"english-bidirectional-distsim.tagger".
Tagger file name is not 'english-bidirectional-distim.tagger' but 'english-bidirectional-distsim.tagger'.
这篇关于在NLTK Python中使用Stanford POS Tagger时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!