Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28730
| Received | by 10.66.74.225 with SMTP id x1mr2014787pav.45.1347125579981; Sat, 08 Sep 2012 10:32:59 -0700 (PDT) |
|---|---|
| Received | by 10.68.136.7 with SMTP id pw7mr2132865pbb.1.1347125579965; Sat, 08 Sep 2012 10:32:59 -0700 (PDT) |
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!usenet.stanford.edu!4no7672797pbn.1!news-out.google.com!a8ni11616485pbd.1!nntp.google.com!r4no7553087pbs.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sat, 8 Sep 2012 10:32:59 -0700 (PDT) |
| In-Reply-To | <df7ab5f7-c273-4a62-b79a-f364f9c2d3b0@googlegroups.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=221.127.251.76; posting-account=mbqf2AoAAAAgAZURfwG566lEnhttS2f1 |
| NNTP-Posting-Host | 221.127.251.76 |
| References | <df7ab5f7-c273-4a62-b79a-f364f9c2d3b0@googlegroups.com> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <1b672d8e-ea00-4280-a724-8650f5a005ae@googlegroups.com> (permalink) |
| Subject | wordnet NLTK Re: AttributeError: 'list' object has no attribute 'lower' |
| From | Token Type <typetoken@gmail.com> |
| Injection-Date | Sat, 08 Sep 2012 17:32:59 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Lines | 63 |
| Xref | csiph.com comp.lang.python:28730 |
Show key headers only | View raw
I don't know why lemma_list = [synset.lemma_names for synset in synset_list] will lead to such an error.
I have to use extend to solve the problem for lemma_list. The following codes are successful, take all the nouns as an example:
>>> def average_polysemy(pos):
synset_list = list(wn.all_synsets(pos))
sense_number = 0
lemma_list = []
for synset in synset_list:
lemma_list.extend(synset.lemma_names)
for lemma in lemma_list:
sense_number_new = len(wn.synsets(lemma, pos))
sense_number = sense_number + sense_number_new
return sense_number/len(synset_list)
>>> average_polysemy('n')
3
>
> I wrote the following function to solve it. However, it pops up "AttributeError: 'list' object has no attribute 'lower'". Quite confused, I supposed [synset.lemma_names for synset in synset_list] has made all the lemma into a list, hasn't it?
>
>
>
> >>> def average_polysemy(pos):
>
> synset_list = list(wn.all_synsets(pos))
>
> lemma_list = [synset.lemma_names for synset in synset_list]
>
> sense_number = 0
>
> for lemma in lemma_list:
>
> sense_number_new = len(wn.synsets(lemma, pos))
>
> sense_number = sense_number + sense_number_new
>
> return sense_number/len(synset_list)
>
>
>
> >>> average_polysemy('n')
>
>
>
> Traceback (most recent call last):
>
> File "<pyshell#54>", line 1, in <module>
>
> average_polysemy('n')
>
> File "<pyshell#53>", line 6, in average_polysemy
>
> sense_number_new = len(wn.synsets(lemma, pos))
>
> File "C:\Python27\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1191, in synsets
>
> lemma = lemma.lower()
>
> AttributeError: 'list' object has no attribute 'lower'
>
>
>
> Thanks for your tips
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-08 10:13 -0700
wordnet NLTK Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-08 10:32 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-08 13:45 -0400
Re: AttributeError: 'list' object has no attribute 'lower' Cameron Simpson <cs@zip.com.au> - 2012-09-09 09:26 +1000
Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 06:50 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-09 10:29 -0400
Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 07:00 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-09-10 11:52 +0200
Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-14 08:01 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Chris Angelico <rosuav@gmail.com> - 2012-09-15 01:19 +1000
Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-14 08:01 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-14 15:18 +0000
Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 07:19 -0700
Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-09 10:32 -0400
csiph-web