On page 77 of the book natural language processing with Python, we have such an exercise: The polysemy of a word is the number of senses it has. Using WordNet, we can determine that the noun doghas seven senses with len(wn.synsets('dog', 'n')). Compute the average polysemy of nouns, verbs, adjectives, and adverbs according to WordNet.http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html
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 -- http://mail.python.org/mailman/listinfo/python-list