View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Siddharth Patwardhan > WordNet-Similarity-1.04 > WordNet::Similarity::DepthFinder



Annotate this POD


Open  6
View/Report Bugs
Module Version: 1.01   Source   Latest Release: WordNet-Similarity-2.07


WordNet::Similarity::DepthFinder - methods to find the depth of synsets in WordNet taxonomies


use WordNet::QueryData;

use WordNet::Similarity::DepthFinder;

my $wn = WordNet::QueryData->new;

defined $wn or die "Construction of WordNet::QueryData failed";

my $obj = WordNet::Similarity::DepthFinder->new ($wn);

my ($err, $errString) = $obj->getError ();

$err and die $errString;

my @roots = $obj->getTaxonomyRoot (2855301, 'n');

my $taxonomy_depth = $obj->getTaxonomyDepth ($roots[0], 'n');

print "The maximum depth of the car#n#4's taxonomy is $taxonomy_depth\n";

my @depths = $obj->getSynsetDepth (2855301, 'n');

print "The depth of car#n#4 is $depths[0]->[0]\n";


The following methods are provided by this module:

$obj->initialize ($configfile)

Overrides the initialize method in WordNet::Similarity to look for and process depths files. The initialize method of the superclass is also called.

$obj->getSynsetDepth ($offset, $pos)

Returns the depth(s) of the synset denoted by $offset and $pos. The return value is a list of references to arrays. Each array has the form (depth, root).

$obj->getTaxonomyDepth ($offset, $pos)

Returns the maximum depth of the taxonomy rooted at the synset identified by $offset and $pos. If $offset and $pos does not identify a root of a taxonomy, then undef is returned and an error is raised.

$obj->getTaxonomies ($offset, $pos)

Returns a list of the roots of the taxonomies to which the synset identified by $offset and $pos belongs.

getLCSbyDepth($synset1, $synset2, $pos, $mode)

Given two input synsets, finds the least common subsumer (LCS) of them. If there are multiple candidates for the LCS (due to multiple inheritance in WordNet), the LCS with the greatest depth is chosen (i.e., the candidate whose shortest path to the root is the longest).

Parameters: a blessed reference, two synsets, a part of speech, and a mode. The mode must the either the string 'wps' or 'offset'. If the mode is wps, then the two input synsets must be in word#pos#sense format. If the mode is offset, then the input synsets must be WordNet offsets.

Returns: a list of the form ($lcs, $depth) where $lcs is the LCS (in wps format if mode is 'wps' or an offset if mode is 'offset'. $depth is the depth of the LCS in its taxonomy. Returns undef on error.

$obj->_processSynsetsFile ($filename)

Reads and processes a synsets file as output by

$obj->_processTaxonomyFile ($filename)

Reads and processes a taxonomies file as produced by


 Ted Pedersen, University of Minnesota Duluth
 tpederse at

 Jason Michelizzi, University of Minnesota Duluth
 mich0212 at



To report bugs, e-mail tpederse at or go to


WordNet::Similarity(3) WordNet::Similarity::wup(3) WordNet::Similarity::lch(3)


Copyright (c) 2005, Ted Pedersen and Jason Michelizzi

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 and is included in this distribution as GPL.txt.

syntax highlighting: