Word2vec::Lesk - Word2vec-Interface Utility Module.
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my $string_a = "This is a test string"; my $string_b = "This is another test string"; my $lesk_score = $lesk->CalculateLeskScore( $string_a, $string_b ); my $cosine_score = $lesk->CalculateCosineScore( $string_a, $string_b ); my $f_score = $lesk->CalcualteFScore( $string_a, $string_b ); print( "Lesk Score: $lesk_score\n" ); print( "Cosine Score: $cosine_score\n" ); print( "F Score: $f_score\n" ); undef( $lesk ); or my $lesk = Word2vec::Lesk->new(); my $string_a = "This is a test string"; my $string_b = "This is another test string"; my %results = %{ $lesk->CalculateAllScores( $string_a, $string_b ) }; for my $key ( sort keys %results ) { print "$key: $results{ $key }\n"; } undef( %results ); undef( $lesk );
Word2vec::Lesk is a module of Lesk functions for the Word2vec::Interface package. Lesk, Raw Lesk, Cosine, F, Recall and Precision scores are all calculated and returned to the used based on phrase/feature overlap between two strings.
Description:
Returns a new "Word2vec::Lesk" module object. Note: Specifying no parameters implies default options. Default Parameters: debugLog = 0 writeLog = 0
Input:
$debugLog -> Instructs module to print debug statements to the console. (1 = True / 0 = False) $writeLog -> Instructs module to print debug statements to a log file. (1 = True / 0 = False)
Output:
Word2vec::Lesk object.
Example:
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); undef( $lesk );
Removes Word2vec::Lesk object from memory.
None
See above example for "new" function. Note: Destroy function is also automatically called during global destruction when exiting the program.
Given two strings, this returns a hash of all overlapping (matching) features between both strings and their frequency counts.
$string_a -> First comparison string $string_b -> Second comparison string
$hash_ref -> Returns a hash table reference with keys being the unique matching feature between two input string parameters and the value as the frequency count of each unique feature.
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my %matching_features = %{ $lesk->GetMatchingFeatures( "I like to eat cookies", "Sometimes I like to eat cookies" ) }; for my $feature ( sort keys %matching_features ) { print "$feature : $matching_features{ $feature }\n"; } undef( %matching_features ); undef( $lesk );
Given two strings, this returns a hash of all overlapping (matching) phrases between both strings and their frequency counts. This prioritizes longer phrases as higher priority when matching.
$hash_ref -> Returns a hash table reference with keys being the unique matching phrase between two input string parameters and the value as the frequency count of each unique phrase.
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my %phrase_overlaps = %{ $lesk->GetPhraseOverlap( "I like to eat cookies", "Sometimes I like to eat cookies" ) }; for my $phrase ( sort keys %phrase_overlaps ) { print "$phrase : $phrase_overlaps{ $phrase }\n"; } undef( %phrase_overlaps ); undef( $lesk );
Given two strings, this returns a lesk score based on overlapping (matching) features between both strings.
$score -> Lesk Score (Float)
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my $lesk_score = $lesk->CalculateLeskScore( "I like to eat cookies", "Sometimes I like to eat cookies" ); print "Lesk Score: $lesk_score\n"; undef( $lesk );
Given two strings, this returns a cosine score based on overlapping (matching) features between both strings.
$score -> Cosine Score (Float)
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my $cosine_score = $lesk->CalculateCosineScore( "I like to eat cookies", "Sometimes I like to eat cookies" ); print "Cosine Score: $cosine_score\n"; undef( $lesk );
Given two strings, this returns a F score based on overlapping (matching) features between both strings.
$score -> F Score (Float)
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my $f_score = $lesk->CalculateFScore( "I like to eat cookies", "Sometimes I like to eat cookies" ); print "F Score: $f_score\n"; undef( $lesk );
Given two strings, this returns a list of scores (F, Cosine, Lesk, Raw Lesk, Precision, Recall), frequency counts (features, phrases, string lengths).
$result_hash -> Hash reference containing: Lesk, Raw Lesk, F, Precision, Recall, Cosine, Matching Feature Frequency, Matching Phrase Frequency, String A Length and String B Length.
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my %scores = %{ $lesk->CalculateAllScores( "I like to eat cookies", "Sometimes I like to eat cookies" ) }; for my $score_name ( sort keys %scores ) { print "$score_name : $scores{ $score_name }\n"; } undef( $lesk );
Returns the _debugLog member variable set during Word2vec::Lesk object initialization of new function.
$value -> '0' = False, '1' = True
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new() my $debugLog = $lesk->GetDebugLog(); print( "Debug Logging Enabled\n" ) if $debugLog == 1; print( "Debug Logging Disabled\n" ) if $debugLog == 0; undef( $lesk );
Returns the _writeLog member variable set during Word2vec::Lesk object initialization of new function.
use Word2vec::Lesk; my $lesk = Word2vec::Lesk->new(); my $writeLog = $lesk->GetWriteLog(); print( "Write Logging Enabled\n" ) if $writeLog == 1; print( "Write Logging Disabled\n" ) if $writeLog == 0; undef( $lesk );
Prints passed string parameter to the console, log file or both depending on user options. Note: printNewLine parameter prints a new line character following the string if the parameter is undefined and does not if parameter is 0.
$string -> String to print to the console/log file. $value -> 0 = Do not print newline character after string, all else prints new line character including 'undef'.
use Word2vec::Lesk: my $lesk = Word2vec::Lesk->new(); $lesk->WriteLog( "Hello World" ); undef( $lesk );
Clint Cuffy, Virginia Commonwealth University
Copyright (c) 2016
Bridget T McInnes, Virginia Commonwealth University btmcinnes at vcu dot edu Clint Cuffy, Virginia Commonwealth University cuffyca at vcu dot edu
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.
To install Word2vec::Interface, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Word2vec::Interface
CPAN shell
perl -MCPAN -e shell install Word2vec::Interface
For more information on module installation, please visit the detailed CPAN module installation guide.