Sense keys from wordnet

1,081 views
Skip to first unread message

Keith Stevens

unread,
Feb 8, 2009, 11:46:12 PM2/8/09
to nltk-...@googlegroups.com
Hello NLTK,

I've been using the wordnet interface for a few projects, and i'm hoping to use it to do some things with Senseval data, and i am wondering how one could extract the sense key number, i.e. something like skill%1:09:01:: for skill.n.01.  Is there a simple method to do this?  looking at the documentation i can't see anything, but perhaps i've glossed over something.

Thanks!
--Keith Stevens

Sandra Derbring

unread,
Feb 9, 2009, 3:49:21 AM2/9/09
to nltk-...@googlegroups.com
Hi Keith,

I don't know if this is what you're looking for, but when I used WordNet to extract information for an application, I did this clause to get what I wanted: (this is written in python so it's not a built-in function in the nltk)

        # Divides all lines from the file into different parts and creates them as posts in the dictionary.
        # A line looks like this: (taken from the file index.sense)
        # acceleration%1:28:00:: 15075190 3 1 (lemma, pos, offset, sense, freq)

        for line in countlist:
            sense_key, offset, sense, freq = line.split()
            lemma, rest = sense_key.split('%')
            ss_type = rest[0]

As you see, the first line in the if-clause is the only one you need if you're not want to split it up further as I did. I'm not sure what you mean with skill.n.01, but if you want to do this only for the noun skill, you can always limit your clause to only those words in the N dictionary. (And of course you can write other conditions too in your clause).

I think I did it this way as I didn't find a simple way to just extract it automatically from nltk, but if anyone else has a way of doing this, I'm interested to hear about it.

Cheers,
Sandra

2009/2/9 Keith Stevens <fozzie...@gmail.com>

吴轲

unread,
Feb 9, 2009, 4:07:53 AM2/9/09
to nltk-...@googlegroups.com
Hi!

2009/2/9 Keith Stevens <fozzie...@gmail.com>

Hello NLTK,

I've been using the wordnet interface for a few projects, and i'm hoping to use it to do some things with Senseval data, and i am wondering how one could extract the sense key number, i.e. something like skill%1:09:01:: for skill.n.01.  Is there a simple method to do this?  looking at the documentation i can't see anything, but perhaps i've glossed over something. 
 
The `key' field in a Lemma object has what you need. There are many methods to get the lemma you need. For example,

# the exmaple code
from nltk.corpus import wordnet as wn
# get all lemmas for a word first then pick the right one.
l = wn.lemmas('skill') # l == [Lemma('skill.n.01.skill'), Lemma('skill.n.02.skill')]
l[0].key # >>> 'skill%1:09:01::'
# another method: find the synset first, pick the right lemma there.
s = wn.synset('skill.n.01')
s.lemmas # >>> [Lemma('skill.n.01.skill'), ... ]
s.lemmas[0].key # >>> 'skill%1:09:01::'



Thanks!
--Keith Stevens



Hope it helps.

- Wu Ke

Steven Bird

unread,
Feb 9, 2009, 4:42:46 AM2/9/09
to nltk-...@googlegroups.com
2009/2/9 Keith Stevens <fozzie...@gmail.com>:

FYI here's our high-level documentation for WordNet, which mentions sense keys:

http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html

If you discover any gaps in this or other documentation, please report it at:
http://code.google.com/p/nltk/issues

-Steven Bird

Keith Stevens

unread,
Feb 9, 2009, 1:44:09 PM2/9/09
to nltk-...@googlegroups.com
Excellent, this is precisely what i was looking for, and missed in the HowTo part.

Thanks!
--Keith Stevens

zhuz...@gmail.com

unread,
May 24, 2016, 6:41:32 AM5/24/16
to nltk-users, fozzie...@gmail.com
Hello,
    I want to ask how can I get the synset by the key, for example, I know a key as skill%1:09:01, how can I get the synset from this key.

Thanks!

在 2009年2月9日星期一 UTC+8下午12:46:12,Keith Stevens写道:

Francis Bond

unread,
May 24, 2016, 7:56:43 AM5/24/16
to nltk-users, fozzie...@gmail.com
G'day,


>>> from nltk.corpus import wordnet
>>> wordnet.lemma_from_key('skill%1:09:01::').synset()
Synset('skill.n.01')

Note that your key was missing two colons. It is 'skill%1:09:01::'
not ''skill%1:09:01'.

I hope that helps.
> --
> You received this message because you are subscribed to the Google Groups
> "nltk-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nltk-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Francis Bond <http://www3.ntu.edu.sg/home/fcbond/>
Division of Linguistics and Multilingual Studies
Nanyang Technological University
Reply all
Reply to author
Forward
0 new messages