使用python textblob库标记器时出错 [英] Error when using python textblob library tagger

查看:129
本文介绍了使用python textblob库标记器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让textblob库运行了一段时间,但决定安装(使用easy_install)一个附加库(

I had the textblob library working fine for a while, but decided to install (using easy_install) an additional library (page here) claiming faster and more accurate tagging.

我无法使其正常运行,因此我将其卸载了,但似乎与TextBlob中的标记功能一团糟.我已经使用pip和easy_install多次卸载并重新安装了nltk和TextBlob,并确保它们是最新的.

I couldn't get it working so I uninstalled it, but it seems to have messed with the tagging function in TextBlob. I've uninstalled and reinstalled both nltk and TextBlob numerous times with both pip and easy_install, and made sure they're up to date.

这是一个生成错误的简单脚本的示例:

Here is an example of a simple script which generates the error:

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>

您可以看到该错误实际上提到了感知器标记器.有什么方法可以更彻底地删除替代标记器的引用吗?

You can see that the error actually mentions the perceptron tagger. Is there any way to more thoroughly remove any references there may be to the alternate tagger?

还请注意,只有标签"功能受到了影响.

Also note that only the "tags" function has been affected.

推荐答案

我发现了为什么使用ap tagger遇到麻烦. 我的问题已在此处解决.更具体地说,通过注释另一种选择是安装nltk,然后将从textblob.packages import nltk"更改为在taggers.py中"导入nltk.

I found out why I was having trouble with the ap tagger. My issue is solved here. More specifically, by the comment "Another option is to install nltk and then change "from textblob.packages import nltk" to "import nltk" [in the taggers.py] file."

(请注意,这与上面的错误消息不符:该错误在没有安装aptagger的情况下出现.我在安装了 时遇到了另一个错误,这是一个解决方案. )

(Note that this doesn't correspond to the error message above: that error was coming up without aptagger installed. I was getting another error with it installed, and this is a solution for that.)

这篇关于使用python textblob库标记器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆