smilly has asked for the wisdom of the Perl Monks concerning the following question:
I tried to run my programme using WordNet::Similarity module which works in ommandlines for me but i get the undef values in my output matrix while my input is a simple 4 words corpus(each word per line). any special reason?
output :
#! /usr/local/bin/perl -w use strict; use warnings; use WordNet::QueryData; use WordNet::Similarity::random; use WordNet::Similarity::path; use WordNet::Similarity::wup; use WordNet::Similarity::lch; use WordNet::Similarity::jcn; use WordNet::Similarity::res; use WordNet::Similarity::lin; use WordNet::Similarity::hso; use WordNet::Similarity::lesk; use WordNet::Similarity::vector; use WordNet::Similarity::vector_pairs; use Data::Dumper; my $Infile = shift; my $Outfile = shift; my $Measure = shift; my (@sim , $simi); unless (defined $Infile and defined $Outfile and defined $Measure) { print STDERR "Undefined input\n"; print STDERR "Usage: simmat.pl inputfile outputfile measure()\n"; exit 1; } print STDERR "Loading WordNet... "; my $wn = WordNet::QueryData->new; die "Unable to create WordNet object.\n" if(!$wn); print STDERR "done.\n"; open (INPUT, "$Infile") || die "can't open the input file"; my @words = <INPUT>; close (INPUT) ; for my $i (0 .. $#words) { for my $j ( ($i+1) .. $#words) { $sim[$i][$j] = similarity( $words[$i], $words[$j]); $sim[$j][$i] = $sim[$i][$j]; } } sub similarity { my ( $w1, $w2 ) = @_; $simi = 1; my $obj = $Measure -> new($wn); my $simi = $obj-> getRelatedness("$w1#n#1", "$w2#n#1"); return $simi; } open (OUTPUT, ">$Outfile"); print OUTPUT Dumper(\@sim); close(OUTPUT);
output :
$VAR1 = [ [ undef, undef, undef, undef ], [ undef, undef, undef, undef ], [ undef, undef, undef, undef ], [ undef, undef, undef ] ];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 'undef' in the matrix instead of values!!!
by halley (Prior) on Feb 06, 2008 at 13:49 UTC | |
by smilly (Novice) on Feb 06, 2008 at 14:12 UTC | |
by citromatik (Curate) on Feb 06, 2008 at 14:57 UTC | |
by smilly (Novice) on Feb 08, 2008 at 03:33 UTC | |
by smilly (Novice) on Feb 08, 2008 at 02:29 UTC | |
Re: 'undef' in the matrix instead of values!!!
by apl (Monsignor) on Feb 06, 2008 at 13:33 UTC | |
by Anonymous Monk on Feb 06, 2008 at 13:41 UTC | |
by apl (Monsignor) on Feb 06, 2008 at 14:07 UTC |
Back to
Seekers of Perl Wisdom