【问题标题】:AttributeError: can't set attribute from nltk.book import *AttributeError:无法从 nltk.book 导入中设置属性 *
【发布时间】:2015-10-04 06:06:56
【问题描述】:

安装 nltk 后,我导入 nltk,然后使用 nltk.download(),但是当我尝试使用此“从 nltk.book 导入 *”时,它显示属性错误。 from nltk.corpus import * 和 from nltk import * 工作正常

我是自然语言处理的新手,所以我对此不太了解,请帮助

从 nltk.book 导入 * * NLTK 书籍的介绍性示例 *

正在加载 text1, ..., text9 和 sent1, ..., sent9

键入文本或句子的名称以查看它。

键入:'texts()' 或 'sents()' 列出材料。

Traceback(最近一次调用最后一次):

文件“”,第 1 行,在

from nltk.book import *

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\book.py”,行 19、在

text1 = Text(gutenberg.words('melville-moby_dick.txt'))

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\text.py”,第 295 行,在 init

tokens = list(tokens)

文件“C:\Program Files (x86)\Python 3.5\lib\site-

packages\nltk\corpus\reader\util.py",第 233 行,在 len

for tok in self.iterate_from(self._toknum[-1]): pass

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\corpus\reader\util.py”,第 291 行,在 iterate_from

tokens = self.read_block(self._stream)

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\corpus\reader\plaintext.py”,第 117 行,在 _read_word_block words.extend(self._word_tokenizer.tokenize(stream.readline()))

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\tokenize\regexp.py”,第 126 行,在 tokenize self._check_regexp()

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\tokenize\regexp.py”,第 121 行,在 _check_regexp self._regexp = compile_regexp_to_noncapturing(self._pattern, self._flags)

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\internals.py”,第 56 行,在 compile_regexp_to_noncapturing return sre_compile.compile(convert_regexp_to_noncapturing_parsed(sre_parse.parse(pattern)), flags=flags)

文件“C:\Program Files (x86)\Python 3.5\lib\site-packages\nltk\internals.py”,第 52 行,在 convert_regexp_to_noncapturing_parsed parsed_pa​​ttern.pattern.groups = 1

AttributeError: 无法设置属性

【问题讨论】:

    标签: python nltk python-3.5


    【解决方案1】:

    我不确定您是否解决了我们的问题。 以防万一,这里也报告了同样的问题: https://github.com/nltk/nltk/issues/1135

    解决方案: https://github.com/nltk/nltk/issues/1106

    “我能够通过进入nltk 目录中的internals.py 文件并删除parsed_pattern.pattern.groups = 1 行来解决此问题。我这样做的理由是,在阅读了一些代码之后,@987654323 @ of sre_parse.py NLTK 被设计为工作存储 groups 作为 sre_parse.Pattern 类的实例的属性。Python 3.5 附带的版本将 groups 作为返回的属性存储(我不太熟悉属性,但这是我认为它所做的)subpattern 列表的长度。The code I'm talking about is here at about line 75. 我不知道这样做的长期影响是什么,我只是想出了这个解决方案通过跟踪代码,我还没有查看从长远来看这可能会导致什么错误。有人请告诉我这是否会导致问题以及是否有更好的解决方案。”

    到目前为止,上述方法对我有用,没有任何问题。

    【讨论】:

      猜你喜欢
      • 2022-01-10
      • 2015-02-08
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多