我试图在NLTK中使用Stanford POS Tagger,但我无法运行此处给出的示例代码 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())
我已经添加了环境变量
CLASSPATH = D:/stanford-postagger/stanford-postagger.jar
STANFORD_MODELS = D:/stanford-postagger/models/
这是我不断得到的错误
回溯(最近的呼叫最后):
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)
但它也没有解决问题。 请帮我解决这个问题。
其他信息: 我在用 Windows 7 64位 Python 2.7 32位 NLTK 2.0