【问题标题】:Error using Stanford POS Tagger in NLTK Python在 NLTK Python 中使用斯坦福 POS 标记器时出错
【发布时间】:2014-05-20 18:04:41
【问题描述】:

我正在尝试在 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/

这是我不断收到的错误

Traceback(最近一次调用最后一次):

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)

但它也不能解决问题。 请帮我解决这个问题。

其他信息: 我在用 视窗 7 64 位 Python 2.7 32 位 NLTK 2.0

【问题讨论】:

  • 我注意到您在环境路径中使用了正斜杠 (/) - 在 Windows 上它应该是反斜杠 ()。此外,请尝试从与模型相同的目录运行它以避免路径问题。
  • 我也尝试过使用反斜杠。没用。
  • 也尝试更改目录,但没有用
  • 尝试解压模型 jar 并确保在路径 STANFORD_MODELS\edu\stanford\nlp\models\pos-tagger\english-bidirectional\ 中有 english-bidirectional-distim.tagger 文件,其中定义了 STANFORD_MODELS 或者是脚本的 CWD
  • @jkoreska:不正确,Windows 至少从 2003 年开始就允许使用正斜杠。Python 中首选正斜杠,因为您不会进入转义字符串和原始字符串 (r'')

标签: python-2.7 nltk stanford-nlp pos-tagger


【解决方案1】:

注意:只是将其发布为答案,以防其他人将来遇到此问题

我终于发现我做错了什么......原来是一个错误。

标记文件名不是 'english-bidirectional-dstim.tagger' 但 'english-bidirectional-distim.tagger'。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多