Re: [nltk-users] The method of insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

192 views
Skip to first unread message

Alex Rudnick

unread,
Sep 3, 2012, 10:18:08 PM9/3/12
to nltk-...@googlegroups.com
Hey there,

The question here: what type of an object is "text" here? If it's a
list of strings, then you're set, but if it's a
ConcatenatedCorpusView, then apparently that won't work! Can you get a
list of words out of your text before passing it to your hedge
function?

On Sun, Sep 2, 2012 at 12:37 AM, typetoken <type...@gmail.com> wrote:
> I want to insert 'like' at the end of every other 3 words in a text. Then I
> use the method of insert as follows:
>
>>>> def hedge(text):
> for i in range(0, len(text),3):
> text.insert(i,'like')
>
>>>> hedge(text)
>
> Traceback (most recent call last):
> File "<pyshell#33>", line 1, in <module>
> hedge(text)
> File "<pyshell#32>", line 3, in hedge
> text.insert(i,'like')
> AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
>
> Quite puzzled? Isn't text here a list? Why doesn't it has the method insert?
>
> Then I test insert as follows. It did exist in python.
>>>> text = ['The', 'Fulton', 'County', 'Grand']
>>>> text.insert(3,'like')
>>>> text
> ['The', 'Fulton', 'County', 'like', 'Grand']
>
> Thanks very much.

--
-- alexr

John H. Li

unread,
Sep 4, 2012, 12:08:14 AM9/4/12
to nltk-...@googlegroups.com
Alex, Thanks for kind reply when I am feeling hopeless and helpless . I don't know if my reply will reach you or not. My post is somehow under censored now. 
My testing is as follows:

>>> import nltk
>>> text = nltk.corpus.brown.words(categories = 'news')
>>> text[:10]
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of']
>>> type(text)
<class 'nltk.corpus.reader.util.ConcatenatedCorpusView'>
>>> 

yes, it's a ConcatenatedCorpusView. However, I can still get a
list of words out of my text before passing it to your hedge
function, say, 
>>> text[:10]
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of']




--



Michael Deeringer

unread,
Sep 7, 2012, 2:25:30 PM9/7/12
to nltk-...@googlegroups.com
Please see your other thread about ConcatenatedCorpusView.


--
 
 

Reply all
Reply to author
Forward
0 new messages