nltk pos_tag用法

问题描述 投票:8回答:3

我试图在NLTK中使用语音标记并使用此命令:

>>> text = nltk.word_tokenize("And now for something completely different")

>>> nltk.pos_tag(text)

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
nltk.pos_tag(text)
File "C:\Python27\lib\site-packages\nltk\tag\__init__.py", line 99, in pos_tag
tagger = load(_POS_TAGGER)
File "C:\Python27\lib\site-packages\nltk\data.py", line 605, in load
resource_val = pickle.load(_open(resource_url))
File "C:\Python27\lib\site-packages\nltk\data.py", line 686, in _open
return find(path).open()
File "C:\Python27\lib\site-packages\nltk\data.py", line 467, in find
raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found.  Please use the NLTK Downloader to obtain the resource:

但是,我收到一条错误消息,显示:

engish.pickle not found.

我已下载整个语料库,并且max.treebank_pos_tagger中有english.pickle文件。

我该怎么做才能让它发挥作用?

nltk pos-tagging
3个回答
6
投票

您的Python安装无法访问maxent或treemap。

首先,检查标记器是否确实存在:从命令行启动Python。

>>> import nltk

然后你可以检查使用

>>> dir (nltk)

仔细查看列表,看看maxenttreebank是否都存在。

打字比较容易

>>> "maxent" in dir(nltk)
>>> True
>>> "treebank" in dir(nltk)
>>> True

使用nltk.download() - > Models选项卡并检查treemap标记符是否显示为已安装。您还应该尝试再次下载标记器。


2
投票

如果你不想使用下载器gui,你可以在python或ipython shell中使用以下命令:

import nltk
nltk.download('punkt')
nltk.download('maxent_treebank_pos_tagger')

0
投票

超过50个语料库和词汇资源,如WordNet:http://www.nltk.org/nltk_data/是免费的。使用http://nltk.github.com/nltk_data/作为服务器索引而不是googlecode Google代码401:需要授权

© www.soinside.com 2019 - 2024. All rights reserved.