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


Groups > comp.lang.python > #30928

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'predefined': 0.07; 'semantic': 0.07; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'teh': 0.09; 'url:googlecode': 0.09; 'index': 0.13; 'dictionary.': 0.16; 'pairs': 0.16; 'pairs,': 0.16; 'pairs:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:w 70': 0.16; 'subject: \n ': 0.16; 'url:svn': 0.16; 'values?': 0.16; 'wrote:': 0.17; 'element': 0.17; 'skip:{ 20': 0.17; 'url:moin': 0.17; 'issue.': 0.20; 'sort': 0.21; 'import': 0.21; 'elements': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'url:wiki': 0.26; '(e.g.': 0.27; 'first,': 0.27; 'i.e.': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:list': 0.28; '>>>>': 0.29; 'dictionary': 0.29; 'case,': 0.29; 'words': 0.29; "skip:' 10": 0.30; 'url:python': 0.32; '(2)': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; 'to:addr:python- list': 0.33; "can't": 0.34; '(1)': 0.34; 'thanks': 0.34; 'list': 0.35; 'follows:': 0.35; 'skip:k 20': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'url:org': 0.36; 'rather': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'skip:w 30': 0.61; 'save': 0.61; 'solve': 0.62; 'close': 0.63; 'score': 0.75; 'exercise.': 0.84; 'subject:value': 0.84; 'url:book': 0.84; 'received:2': 0.91; 'rank': 0.95; 'ranking': 0.97
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?
Date Sun, 07 Oct 2012 18:49:52 +0100
References <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-2-98-195-10.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120907 Thunderbird/15.0.1
In-Reply-To <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com>
X-Antivirus avast! (VPS 121007-1, 07/10/2012), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1928.1349632173.27098.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349632173 news.xs4all.nl 6976 [2001:888:2000:d::a6]:33971
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30928

Show key headers only | View raw


On 07/10/2012 17:15, Token Type wrote:
> In order to solve the following question, http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html:
> ★ Use one of the predefined similarity measures to score the similarity of each of the following pairs of words. Rank the pairs in order of decreasing similarity. How close is your ranking to the order given here, an order that was established experimentally by (Miller & Charles, 1998): car-automobile, gem-jewel, journey-voyage, boy-lad, coast-shore, asylum-madhouse, magician-wizard, midday-noon, furnace-stove, food-fruit, bird-cock, bird-crane, tool-implement, brother-monk, lad-brother, crane-implement, journey-car, monk-oracle, cemetery-woodland, food-rooster, coast-hill, forest-graveyard, shore-woodland, monk-slave, coast-forest, lad-wizard, chord-smile, glass-magician, rooster-voyage, noon-string.
>
> (1) First, I put the word pairs in a list eg.
> pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. According to http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html, I need to put them in the following format so as to calculate teh semantic similarity : wn.synset('right_whale.n.01').path_similarity(wn.synset('minke_whale.n.01')).
>
> In this case, I need to use loop to iterate each element in the above pairs. How can I refer to each element in the above pairs, i.e. pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. What's the index for 'car' and for 'automobile'? Thanks for your tips.
>
> (2) Since I can't solve the above index issue. I try to use dictionary as follows:
>>>> import nltk
>>>> from nltk.corpus import wordnet as wn
>>>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'}
>>>> for key in pairs:
> 	word1 = wn.synset(str(key) + '.n.01')
> 	word2 = wn.synset(str(pairs[key])+'.n.01')
> 	similarity = word1.path_similarity(word2)
> 	print key+'-'+pairs[key],similarity
>
> 	
> car-automobile 1.0
> journey-voyage 0.25
> gem-jewel 0.125
>
> Now it seems that I can calculate the semantic similarity for each groups in the above dictionary. However, I want to sort according to the similarity value in the result before print the result out. Can sort dictionary elements according to their values? This is one of the requirement in this exercise. How can we make each group of words (e.g. car-automobile, jounrney-voyage, gem-jewel)
> sorted according to their similarity value?
> Thanks for your tips.
>

In your for loop save the data in a list rather than print it out and 
sort according to this 
http://wiki.python.org/moin/HowTo/Sorting#Operator_Module_Functions

-- 
Cheers.

Mark Lawrence.

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