Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30992

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

Newsgroups comp.lang.python
Date 2012-10-08 20:23 -0700
References <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> <mailman.1928.1349632173.27098.python-list@python.org> <mailman.1978.1349752402.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.1979.1349753013.27098.python-list@python.org> (permalink)

Show all headers | View raw


Dear all, the problem has been solved as follows. Thanks anyway:
>>> import nltk
>>> from nltk.corpus import wordnet as wn
>>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'}
>>> list_simi=[]
>>> for key in pairs:
	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))

        
>>> from operator import itemgetter
>>> sorted(list_simi, key=itemgetter(1), reverse=False)
[('gem-jewel', 0.125), ('journey-voyage', 0.25), ('car-automobile', 1.0)]
>>> sorted(list_simi, key=itemgetter(1), reverse=True)
[('car-automobile', 1.0), ('journey-voyage', 0.25), ('gem-jewel', 0.125)]
>>> sorted(list_simi, key=itemgetter(1))
[('gem-jewel', 0.125), ('journey-voyage', 0.25), ('car-automobile', 1.0)]

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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