Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
typetoken  
View profile  
 More options Sep 2 2012, 12:32 am
From: typetoken <typeto...@gmail.com>
Date: Sat, 1 Sep 2012 21:32:00 -0700 (PDT)
Subject: The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

I want to add  'like' at the end of every other 3 words in a text. Then I
try to use insert as follows. However, it told me that "AttributeError:
'ConcatenatedCorpusView' object has no attribute 'insert'". Quite puzzled?
Isn't text a list here? If it is a list, why doesn't not insert work here?

>>> text = nltk.corpus.brown.words(categories = 'news')
>>> 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'

Further more, I test the function of insert. It did work as follows:

>>> text = ['The', 'Fulton', 'County', 'Grand']
>>> text.insert(3,'like')
>>> text

['The', 'Fulton', 'County', 'like', 'Grand']


Thanks for your instructions!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven Bird  
View profile  
 More options Sep 2 2012, 10:18 pm
From: Steven Bird <stevenbi...@gmail.com>
Date: Mon, 3 Sep 2012 12:18:37 +1000
Local: Sun, Sep 2 2012 10:18 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
The problem here is that you are trying to access an NLTK corpus
object as if it was a list object.  However, you can convert it to a
list like this:

text = list(nltk.corpus.brown.words(categories = 'news'))

-Steven Bird

On 2 September 2012 14:32, typetoken <typeto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John H. Li  
View profile  
 More options Sep 2 2012, 10:45 pm
From: "John H. Li" <typeto...@gmail.com>
Date: Mon, 3 Sep 2012 10:44:35 +0800
Local: Sun, Sep 2 2012 10:44 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

Thanks very much indeed.

Isn't text in NLTK corpus in a list format already?  I am puzzled. I tested
the text from nltk as follows. It is a list actually. See the following:

>>> text = nltk.corpus.brown.words(categories = 'news')
>>> text[:10]

['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an',
'investigation', 'of']

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven Bird  
View profile  
 More options Sep 2 2012, 10:48 pm
From: Steven Bird <stevenbi...@gmail.com>
Date: Mon, 3 Sep 2012 12:47:52 +1000
Local: Sun, Sep 2 2012 10:47 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
No, an NLTK corpus reader is not a list, but you can convert it to a list:

>>> text = nltk.corpus.brown.words(categories = 'news')
>>> type(text)

<class 'nltk.corpus.reader.util.ConcatenatedCorpusView'>
>>> text = list(nltk.corpus.brown.words(categories = 'news'))
>>> type(text)

<type 'list'>

On 3 September 2012 12:44, John H. Li <typeto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
peter ljunglöf  
View profile  
 More options Sep 3 2012, 3:23 am
From: peter ljunglöf <peter.ljung...@heatherleaf.se>
Date: Mon, 3 Sep 2012 09:23:10 +0200
Local: Mon, Sep 3 2012 3:23 am
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
3 sep 2012 kl. 04:44 skrev John H. Li:

> Isn't text in NLTK corpus in a list format already?  I am puzzled. I tested the text from nltk as follows. It is a list actually. See the following:
> >>> text = nltk.corpus.brown.words(categories = 'news')
> >>> text[:10]
> ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of']

You did just implicitly convert it to a list:

>>> type(text)

<class 'nltk.corpus.reader.util.ConcatenatedCorpusView'>

>>> type(text[:10])

<type 'list'>

/Peter


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John H. Li  
View profile  
 More options Sep 2 2012, 11:21 pm
From: "John H. Li" <typeto...@gmail.com>
Date: Mon, 3 Sep 2012 11:21:12 +0800
Local: Sun, Sep 2 2012 11:21 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

Thanks indeed for your enlightenment. type(text) does show the truth.
Though NLTK corpus reader is not a list, the slice of the text from the
nltk corpus is still in list format. say,

>>> import nltk
>>> text = nltk.corpus.brown.words(categories = 'news')
>>> type(text)

<class 'nltk.corpus.reader.util.ConcatenatedCorpusView'>
>>> type(text[:10])

<type 'list'>

Isn't it contradictory?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Deeringer  
View profile  
 More options Sep 7 2012, 2:24 pm
From: Michael Deeringer <mdeerin...@gmail.com>
Date: Fri, 7 Sep 2012 14:24:30 -0400
Local: Fri, Sep 7 2012 2:24 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

Per the reply from Peter Ljunglöf, using slice notation on that object
implicitly converts it to a list.

On Sun, Sep 2, 2012 at 11:21 PM, John H. Li <typeto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Deeringer  
View profile  
 More options Sep 7 2012, 2:29 pm
From: Michael Deeringer <mdeerin...@gmail.com>
Date: Fri, 7 Sep 2012 14:29:10 -0400
Local: Fri, Sep 7 2012 2:29 pm
Subject: Re: [nltk-users] The Method of Insert doesn't work. AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'

When in doubt, help(ClassName) or help(variable_name) at the Python prompt
will tell you all about that class/object, pulling straight from the
docstring. For a quick list of attributes, you can use dir instead of help.

~Michael

On Fri, Sep 7, 2012 at 2:24 PM, Michael Deeringer <mdeerin...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »