Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?
#! /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 ] ];

In reply to 'undef' in the matrix instead of values!!! by smilly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found