WordNet::SenseKey - convert WordNet sense keys to sense numbers, and v.v.
use WordNet::QueryData; use WordNet::SenseKey; my $wn = WordNet::QueryData->new("/usr/share/wordnet"); my $sk = WordNet::SenseKey->new($wn); my $skey = $sk->get_sense_key("run#v#2"); print "Found the sense key $skey for run#v#2\n"; my $sense = $sk->get_sense_num($skey); print "Found sense $sense for key $skey\n"; my @synset = $sk->get_synset($skey); print "Synset is @synset\n"; my $can = $sk->get_canonical_sense("escape", "run%2:38:04::"); print "Found sense $can\n";
The WordNet::Similarity package is designed to work with words in the form of lemma#pos#num where "lemma" is the word lemma, "pos" is the part of speech, and "num" is the sense number. Unfortuantely, the sense numbering is not stable from one WordNet release to another. Thus, for external programs, it can often be more useful to work with sense keys. Unfortunately, the Wordnet::Similarity package is unaware of sense keys. This class fills that gap. WordNet senses keys are described in greater detail in http://wordnet.princeton.edu/man/senseidx.5WN.html There are four routines implemented here: get_sense_key($sense); get_sense_num($sense_key); get_synset($sense_key); get_canonical_sense($lemma, $sense_key);
Given a word sense, in the form of lemma#pos#num, this method returns the corresponding sense key, as defined by WordNet. Here, "lemma" is the word lemma, "pos" is the part of speech, and "num" is the sense number. The format of WordNet sense keys is documented in senseidx(5WN), one of the WordNet man pages. Returns an undefined value if the sense key cannot be found. The 'get_sense_num' method performs the inverse operation.
Given a WordNet sense key, this method returns the corresponding word-sense string, in the lemma#pos#num format. This function is the inverse of the get_sense_key method; calling one, and then the other, should always return exactly the original input. Returns an undefined value if the sense cannot be found.
Given a WordNet sense key, this method returns a list of other sense keys that belong to the same synset.
Senses in a synset all have different lemmas. This function selects one particular element of a synset, given a lemma, and any other member of the synset. Thus, for example, run%2:38:04:: and escape%2:38:02:: belong to the same synset. Then get_canonical_sense("escape", "run%2:38:04::"); will return escape%2:38:02::, as this is the sense of "escape" that belongs to the same synset as run%2:38:04::. Returns an undefined value if the sense cannot be found.
senseidx(5WN), WordNet::Similarity(3), WordNet::QueryData(3) http://wordnet.princeton.edu/ http://www.ai.mit.edu/~jrennie/WordNet http://groups.yahoo.com/group/wn-similarity
Linas Vepstas <firstname.lastname@example.org>
Copyright (c) 2008, 2009 Linas Vepstas
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to
The Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Note: a copy of the GNU General Public License is available on the web at <http://www.gnu.org/licenses/gpl.txt> and is included in this distribution as GPL.txt.