Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30990
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-10-08 20:13 -0700 |
| References | <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> <mailman.1928.1349632173.27098.python-list@python.org> |
| Subject | Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? |
| From | Token Type <typetoken@gmail.com> |
| Message-ID | <mailman.1978.1349752402.27098.python-list@python.org> (permalink) |
yes, thanks all your tips. I did try sorted with itemgetter. However, the sorted results are same as follows whether I set reverse=True or reverse= False. Isn't it strange? Thanks.
>>> import nltk
>>> from nltk.corpus import wordnet as wn
>>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'}
>>> for key in pairs:
list_simi=[]
from operator import itemgetter
word1 = wn.synset(str(key) + '.n.01')
word2 = wn.synset(str(pairs[key])+'.n.01')
similarity = word1.path_similarity(word2)
list_simi.append((key+'-'+pairs[key],similarity))
sorted(list_simi, key=itemgetter(1), reverse=True)
[('car-automobile', 1.0)]
[('journey-voyage', 0.25)]
[('gem-jewel', 0.125)]
>>> for key in pairs:
list_simi=[]
from operator import itemgetter
word1 = wn.synset(str(key) + '.n.01')
word2 = wn.synset(str(pairs[key])+'.n.01')
similarity = word1.path_similarity(word2)
list_simi.append((key+'-'+pairs[key],similarity))
sorted(list_simi, key=itemgetter(1), reverse=False)
[('car-automobile', 1.0)]
[('journey-voyage', 0.25)]
[('gem-jewel', 0.125)]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-07 09:15 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-07 18:49 +0100
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-08 20:13 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-08 21:24 -0600
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? alex23 <wuwei23@gmail.com> - 2012-10-08 20:31 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-08 21:16 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? alex23 <wuwei23@gmail.com> - 2012-10-08 22:44 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-09 09:00 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-08 20:13 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-08 20:23 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Token Type <typetoken@gmail.com> - 2012-10-08 20:23 -0700
Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Terry Reedy <tjreedy@udel.edu> - 2012-10-07 15:53 -0400
How to control the internet explorer? yujian <yujian4newsgroup@gmail.com> - 2012-10-08 11:02 +0800
Re: How to control the internet explorer? alex23 <wuwei23@gmail.com> - 2012-10-07 20:37 -0700
csiph-web