nltk pos_tag用法

Ash*_*ngh 8 nltk pos-tagger

我试图在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:
Run Code Online (Sandbox Code Playgroud)

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

engish.pickle not found.
Run Code Online (Sandbox Code Playgroud)

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

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

Ram*_*han 7

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

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

>>> import nltk

然后你可以检查使用

>>> dir (nltk)

通过看列表,看是否maxenttreebank都在那里.

打字比较容易

>>> "maxent" in dir(nltk)
>>> True
>>> "treebank" in dir(nltk)
>>> True
Run Code Online (Sandbox Code Playgroud)

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

NLTK下载器,型号标签