EDITED
此問題已從NLTK v3.2.1解決。升級您的NLTK版本可以解決該問題,例如pip install -U nltk
。
我面臨同樣的問題,遇到的錯誤如下;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\data.py", line 924, in _open
return urlopen(resource_url)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 391, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 414, in _open
'unknown_open', req)
File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1206, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: c>
的URLError你提到的是由於在NLTK庫在Windows中perceptron.py文件中的錯誤。 在我的機器,該文件是在這個位置
C:\Python27\Lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py
(基本上看內你的同等位置,無論你有Python27文件夾)
的錯誤基本上在代碼中找到相應的位置您的機器中的averaged_perceptron_tagger。可以看一下data.py文件中提到的801和924行。
我認爲NLTK開發者社區最近在代碼中修復了這個bug。看看幾天前對代碼做出的承諾。
https://github.com/nltk/nltk/commit/d3de14e58215beebdccc7b76c044109f6197d1d9#diff-26b258372e0d13c2543de8dbb1841252
的片段,其中所述變化是由如下;
self.tagdict = {}
self.classes = set()
if load:
AP_MODEL_LOC = 'file:'+str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
self.load(AP_MODEL_LOC)
# Initially it was:AP_MODEL_LOC = str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
def tag(self, tokens):
將文件更新到最近一次爲我工作的提交,並且能夠使用nltk.pos_tag命令。我相信這也可以解決您的問題(假設您已經設置了其他所有設置)。
的可能的複製[Python的NLTK POS \ _tag拋出URLError](http://stackoverflow.com/questions/35827859/python-nltk-pos-tag-throws-urlerror) – alvas
看起來像耶。我之前讀過那篇文章。 – Max