Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28263
| Date | 2012-09-02 07:10 -0400 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' |
| References | <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.80.1346584263.27098.python-list@python.org> (permalink) |
On 09/02/2012 05:39 AM, Token Type wrote: > I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows: > >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> def hedge(text): > for i in range(3,len(text),4): > new_text = text.insert(i, 'like') > return new_text[:50] > >>>> hedge(text) > Traceback (most recent call last): > File "<pyshell#77>", line 1, in <module> > hedge(text) > File "<pyshell#76>", line 3, in hedge > new_text = text.insert(i, 'like') > AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' > > Isn't text in the brown corpus above a list? why doesn't it has attribute 'insert'? > I tried to find online documentation for nltk, and although I found the mention of a free online book, I didn't see it. So, some generic comments. The error message is telling you that the object 'text' is not a list, but a "ConcatenatedCorpusView". Perhaps you can look that up in your docs for nltk. But there's quite a bit you can do just with the interpreter. try print type(text) to see the type of text. try dir(text) to see what attributes it has try help(text) to see what docstrings might be built in. Incidentally, if you really think it's a list of words (or that it acts like a list), then 'text' might not be the best name for it. Any reason you didn't just call it words ? -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Token Type <typetoken@gmail.com> - 2012-09-02 02:39 -0700 Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Dave Angel <d@davea.name> - 2012-09-02 07:10 -0400 Re: Fwd: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Dave Angel <d@davea.name> - 2012-09-02 09:51 -0400 Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Peter Otten <__peter__@web.de> - 2012-09-02 16:12 +0200
csiph-web