gpt4 book ai didi

python-2.7 - 在 NLTK Python 中使用斯坦福 POS 标记器时出错

转载 作者:行者123 更新时间:2023-12-04 02:07:36 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

我终于发现我做错了什么..结果证明是一个错误。

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

关于python-2.7 - 在 NLTK Python 中使用斯坦福 POS 标记器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22930328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com