关于pos标记器:nltk pos_tag的用法

nltk pos_tag usage

我试图在NLTK中使用语音标记,并使用了以下命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
>>> 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\
ltk\\tag\\__init__.py", line 99, in pos_tag
tagger = load(_POS_TAGGER)
File"C:\\Python27\\lib\\site-packages\
ltk\\data.py", line 605, in load
resource_val = pickle.load(_open(resource_url))
File"C:\\Python27\\lib\\site-packages\
ltk\\data.py", line 686, in _open
return find(path).open()
File"C:\\Python27\\lib\\site-packages\
ltk\\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:

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

1
engish.pickle not found.

我已经下载了整个语料库,并且在maxtent_treebank_pos_tagger中有english.pickle文件

我该怎么做才能使它正常工作?


您的Python安装无法达到maxent或treemap。

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

>>> import nltk

然后您可以检查使用

>>> dir (nltk)

浏览列表以查看maxenttreebank是否都在其中。

更容易键入

1
2
3
4
>>>"maxent" in dir(nltk)
>>> True
>>>"treebank" in dir(nltk)
>>> True

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

NLTK Downloader, Models Tab


如果您不想使用下载程序gui,则可以在python或ipython shell中使用以下命令:

1
2
3
import nltk
nltk.download('punkt')
nltk.download('maxent_treebank_pos_tagger')


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