04 Oct 2015 16:19:03 UTC
- Distribution: WordNet-Similarity
- Module version: 2.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (6)
- Testers (15 / 8 / 0)
- KwaliteeBus factor: 0
- License: open_source
- Activity24 month
- Download (5.5MB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:4 non-PAUSE usersTPEDERSE Ted Pedersenand 1 contributors
- Ted Pedersen, Siddharth Patwardhan, Satanjeev Banerjee, Jason Michelizzi
- CONFIGURATION FILE
- SEE ALSO
- COPYRIGHT AND LICENSE
WordNet::Similarity::hso - Perl module for computing semantic relatedness of word senses using the method described by Hirst and St-Onge (1998).
use WordNet::Similarity::hso; use WordNet::QueryData; my $wn = WordNet::QueryData->new(); my $object = WordNet::Similarity::hso->new($wn); my $value = $object->getRelatedness("car#n#1", "bus#n#2"); ($error, $errorString) = $object->getError(); die "$errorString\n" if($error); print "car (sense 1) <-> bus (sense 2) = $value\n";
This module computes the semantic relatedness of word senses according to the method described by Hirst and St-Onge (1998). In their paper they describe a method to identify 'lexical chains' in text. They measure the semantic relatedness of words in text to identify the links of the lexical chains. This measure of relatedness has been implemented in this module.
This method is internally called to determine the parts of speech this measure is capable of dealing with.
- $hso->getRelatedness ($synset1, $synset2)
Computes the relatedness of two word senses using the method of Hirst & St-Onge.
Parameters: two word senses in "word#pos#sense" format.
Returns: Unless a problem occurs, the return value is the relatedness score, which is greater-than or equal-to 0 and less-than or equal-to 16. If an error occurs, then the error level is set to non-zero and an error string is created (see the description of getError()).
The semantic relatedness modules in this distribution are built as classes that define the following methods:
new() getRelatedness() getError() getTraceString()
See the WordNet::Similarity(3) documentation for details of these methods.
To create an object of the hso measure, we would have the following lines of code in the Perl program.
use WordNet::Similarity::hso; $measure = WordNet::Similarity::hso->new($wn, '/home/sid/hso.conf');
The reference of the initialized object is stored in the scalar variable '$measure'. '$wn' contains a WordNet::QueryData object that should have been created earlier in the program. The second parameter to the 'new' method is the path of the configuration file for the hso measure. If the 'new' method is unable to create the object, '$measure' would be undefined. This, as well as any other error/warning may be tested.
die "Unable to create object.\n" if(!defined $measure); ($err, $errString) = $measure->getError(); die $errString."\n" if($err);
To find the semantic relatedness of the first sense of the noun 'car' and the second sense of the noun 'bus' using the measure, we would write the following piece of code:
$relatedness = $measure->getRelatedness('car#n#1', 'bus#n#2');
To get traces for the above computation:
However, traces must be enabled using configuration files. By default traces are turned off.
The behavior of the measures of semantic relatedness can be controlled by using configuration files. These configuration files specify how certain parameters are initialized within the object. A configuration file may be specififed as a parameter during the creation of an object using the new method. The configuration files must follow a fixed format.
Every configuration file starts with the name of the module ON THE FIRST LINE of the file. For example, a configuration file for the hso module will have on the first line 'WordNet::Similarity::hso'. This is followed by the various parameters, each on a new line and having the form 'name::value'. The 'value' of a parameter is optional (in case of boolean parameters). In case 'value' is omitted, we would have just 'name::' on that line. Comments are supported in the configuration file. Anything following a '#' is ignored till the end of the line.
The module parses the configuration file and recognizes the following parameters:
The value of this parameter specifies the level of tracing that should be employed for generating the traces. This value is an integer equal to 0, 1, or 2. If the value is omitted, then the default value, 0, is used. A value of 0 switches tracing off. A value of 1 or 2 switches tracing on. A trace of level 1 means the synsets are represented as word#pos#sense strings, while for level 2, the synsets are represented as word#pos#offset strings.
The value of this parameter specifies whether or not caching of the relatedness values should be performed. This value is an integer equal to 0 or 1. If the value is omitted, then the default value, 1, is used. A value of 0 switches caching 'off', and a value of 1 switches caching 'on'.
The value of this parameter indicates the size of the cache, used for storing the computed relatedness value. The specified value must be a non-negative integer. If the value is omitted, then the default value, 5,000, is used. Setting maxCacheSize to zero has the same effect as setting cache to zero, but setting cache to zero is likely to be more efficient. Caching and tracing at the same time can result in excessive memory usage because the trace strings are also cached. If you intend to perform a large number of relatedness queries, then you might want to turn tracing off.
perl(1), WordNet::Similarity(3), WordNet::QueryData(3)
Ted Pedersen, University of Minnesota Duluth tpederse at d.umn.edu Siddharth Patwardhan, University of Utah, Salt Lake City sidd at cs.utah.edu
Copyright (c) 2005, Ted Pedersen and Siddharth Patwardhan
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.
Module Install Instructions
To install WordNet::Similarity, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install WordNet::Similarity
For more information on module installation, please visit the detailed CPAN module installation guide.