[英]AttributeError: can't set attribute from nltk.book import *
after installing nltk i import nltk and then use nltk.download() but when i try to use this "from nltk.book import *" it shows attribute error. 安装nltk之后,我导入nltk,然后使用nltk.download(),但是当我尝试使用此“ from nltk.book import *”时,它显示属性错误。 from nltk.corpus import * and from nltk import * works fine
从nltk.corpus import *和从nltk import *正常工作
i am new to natural language processing so i dont know much about this please help 我是自然语言处理的新手,所以我对此不太了解,请帮助
from nltk.book import * * Introductory Examples for the NLTK Book * 来自nltk.book import * * NLTK书的入门示例*
Loading text1, ..., text9 and sent1, ..., sent9 加载text1,...,text9和send1,...,sent9
Type the name of the text or sentence to view it. 键入文本或句子的名称以进行查看。
Type: 'texts()' or 'sents()' to list the materials. 输入:“ texts()”或“ sents()”以列出材料。
Traceback (most recent call last): 追溯(最近一次通话):
File "", line 1, in 文件“”,第1行,位于
from nltk.book import *
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\book.py", line 19, in 文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-packages \\ nltk \\ book.py”,第19行,在
text1 = Text(gutenberg.words('melville-moby_dick.txt'))
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\text.py", line 295, in init 初始化中的文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-packages \\ nltk \\ text.py”,第295行
tokens = list(tokens)
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site- 文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-
packages\\nltk\\corpus\\reader\\util.py", line 233, in len 包\\ nltk \\ corpus \\ reader \\ util.py”,第233行,在len中
for tok in self.iterate_from(self._toknum[-1]): pass
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\corpus\\reader\\util.py", line 291, in iterate_from 文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-packages \\ nltk \\ corpus \\ reader \\ util.py”,第291行,位于iterate_from
tokens = self.read_block(self._stream)
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\corpus\\reader\\plaintext.py", line 117, in _read_word_block words.extend(self._word_tokenizer.tokenize(stream.readline())) 文件“ 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( )))
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\tokenize\\regexp.py", line 126, in tokenize self._check_regexp() 标记为self._check_regexp()的文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-packages \\ nltk \\ tokenize \\ regexp.py”,第126行。
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\tokenize\\regexp.py", line 121, in _check_regexp self._regexp = compile_regexp_to_noncapturing(self._pattern, self._flags) 文件“ 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)
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\internals.py", line 56, in 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”,第56行,在compile_regexp_to_noncapturing中返回sre_compile.compile(convert_regexp_to_noncapturing_parsed(sre_parse.parse(pattern)),标志=标志)
File "C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\nltk\\internals.py", line 52, in convert_regexp_to_noncapturing_parsed parsed_pattern.pattern.groups = 1 文件“ C:\\ Program Files(x86)\\ Python 3.5 \\ lib \\ site-packages \\ nltk \\ internals.py”,第52行,位于convert_regexp_to_noncapturing_parsed parsed_pattern.pattern.groups = 1中
AttributeError: can't set attribute AttributeError:无法设置属性
I am not sure if you worked our your issue. 我不确定您是否解决了我们的问题。 Just in case, same issue also reported here: https://github.com/nltk/nltk/issues/1135
以防万一,这里也报道了同样的问题: https : //github.com/nltk/nltk/issues/1135
Solution: https://github.com/nltk/nltk/issues/1106 解决方案: https : //github.com/nltk/nltk/issues/1106
"I was able to fix this problem by going into the internals.py
file in the nltk
directory and removing the line parsed_pattern.pattern.groups = 1
. My rationale behind this was, after doing a bit of code reading, the original version of sre_parse.py
that NLTK was designed to work stored groups
as an attribute of an instance of the sre_parse.Pattern
class. The version that comes with Python 3.5 stores groups
as a property which returns (I'm not too familiar with properties, but this is what I presume it does) the length of a subpattern
list. The code I'm talking about is here at about line 75. What I don't know is what the long term effects of doing this will be, I came up with this solution just by tracing through the code, I haven't looked at what bugs this may cause in the long run. Someone please tell me if this would cause problems and if there's a better solution." “我能够通过进入
nltk
目录中的internals.py
文件并删除parsed_pattern.pattern.groups = 1
行来解决此问题。我的基本原理是,在经过一些代码阅读之后, 原始版本的sre_parse.py
是NLTK旨在将存储的groups
作为sre_parse.Pattern
类的实例的一个属性来工作的sre_parse.Pattern
随附的版本将groups
存储为返回的属性(我不太熟悉属性,但这这是我想做的) subpattern
列表的长度, 我正在谈论的代码在第75行。我不知道这样做的长期影响,我想出了该解决方案仅通过跟踪代码即可解决,从长远来看,我还没有研究过这可能会导致什么错误。请告诉我这是否会导致问题以及是否有更好的解决方案。”
The above works for me without any issues so far. 到目前为止,以上内容对我来说没有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.