smilly has asked for the wisdom of the Perl Monks concerning the following question:
#! /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(WordNet:: +Similarity::path)\n"; exit 1; } print STDERR "Loading WordNet... \nLoading WordNet::QueryData... "; 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"; chomp (my @words = <INPUT>); close (INPUT) ; for my $i (0 .. $#words) { for my $j ( ($i) .. $#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", "$w2"); return $simi; } open (OUTPUT, ">$Outfile"); print OUTPUT Dumper(\@sim); close(OUTPUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Advice on make my programme faster
by suaveant (Parson) on Feb 11, 2008 at 18:38 UTC | |
|
Re: Advice on make my programme faster
by kyle (Abbot) on Feb 11, 2008 at 19:07 UTC | |
|
Re: Advice on make my programme faster
by roboticus (Chancellor) on Feb 11, 2008 at 21:51 UTC | |
|
Re: Advice on make my programme faster
by lima1 (Curate) on Feb 11, 2008 at 20:44 UTC | |
by smilly (Novice) on Feb 11, 2008 at 21:27 UTC | |
|
Re: Advice on make my programme faster
by downer (Monk) on Feb 12, 2008 at 05:03 UTC |