我让 textblob 库正常工作了一段时间,但决定安装(使用 easy_install)一个额外的库(此处的页面)声称更快、更准确的标记。
我无法让它工作,所以我卸载了它,但它似乎与 TextBlob 中的标记功能混淆了。我已经多次使用 pip 和 easy_install 卸载并重新安装了 nltk 和 TextBlob,并确保它们是最新的。
下面是一个生成错误的简单脚本示例:
from textblob import TextBlob
blob = TextBlob("This is a sentence")
print repr(blob.tags)
并打印错误:
Traceback (most recent call last):
File "tesst.py", line 5, in <module>
print repr(blob.tags)
File "C:\Users\Emmet\Anaconda\lib\site-packages\textblob\decorators.py", line 24, in __get__
value = obj.__dict__[self.func.__name__] = self.func(obj)
File "C:\Users\Emmet\Anaconda\lib\site-packages\textblob\blob.py", line 445, in pos_tags
for word, t in self.pos_tagger.tag(self.raw)
File "C:\Users\Emmet\Anaconda\lib\site-packages\textblob\decorators.py", line 35, in decorated
return func(*args, **kwargs)
File "C:\Users\Emmet\Anaconda\lib\site-packages\textblob\en\taggers.py", line 34, in tag
tagged = nltk.tag.pos_tag(text)
File "C:\Users\Emmet\Anaconda\lib\site-packages\nltk\tag\__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "C:\Users\Emmet\Anaconda\lib\site-packages\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Users\Emmet\Anaconda\lib\site-packages\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Users\Emmet\Anaconda\lib\site-packages\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Users\Emmet\Anaconda\lib\site-packages\nltk\data.py", line 924, in _open
return urlopen(resource_url)
File "C:\Users\Emmet\Anaconda\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Emmet\Anaconda\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Users\Emmet\Anaconda\lib\urllib2.py", line 454, in _open
'unknown_open', req)
File "C:\Users\Emmet\Anaconda\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Users\Emmet\Anaconda\lib\urllib2.py", line 1265, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: c>
您可以看到错误实际上提到了感知器标记器。有没有办法更彻底地删除可能对备用标记器的任何引用?
另请注意,只有“标签”功能受到影响。