from nltk.tag.perceptron import PerceptronTagger
tagger = PerceptronTagger()
def pos_tagging(X):
tagset = None
tokens = nltk.word_tokenize(X)
tags = nltk.tag._pos_tag(tokens, tagset, tagger)
pos_X = map(get_wordnet_pos, tags)
return pos_X
AI.py是我的python文件
Traceback (most recent call last):
File "C:/Users/jpsamaranayake/PycharmProjects/AI/AI.py", line 206, in <module>
tagger = PerceptronTagger()
File "C:\Python27\lib\site-packages\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Python27\lib\site-packages\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Python27\lib\site-packages\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Python27\lib\site-packages\nltk\data.py", line 924, in _open
return urlopen(resource_url)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 454, in _open
'unknown_open', req)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1265, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: c>
答案 0 :(得分:4)
将nltk版本更改为3.1并删除nltk.download()中的先前avareage perceptron标记并再次安装