| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | my $Version = '0.03'; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use WordNet::SenseRelate::WordToSet; | ||
| 9 | use WordNet::QueryData; | ||
| 10 | use Getopt::Long; | ||
| 11 | |||
| 12 | my $measure = 'WordNet::Similarity::lesk'; | ||
| 13 | my $trace = 0; | ||
| 14 | my $config; | ||
| 15 | my $version; | ||
| 16 | my $help; | ||
| 17 | |||
| 18 | my $res = GetOptions ("type|measure=s" => \$measure, | ||
| 19 | "trace=i" => \$trace, | ||
| 20 | "config=s" => \$config, | ||
| 21 | "version" => \$version, | ||
| 22 | "help" => \$help, | ||
| 23 | ); | ||
| 24 | |||
| 25 | unless ($res) { | ||
| 26 | showUsage(); | ||
| 27 | exit 1; | ||
| 28 | } | ||
| 29 | |||
| 30 | if ($version) { | ||
| 31 | print "wordtoset.pl version ", $Version, "\n"; | ||
| 32 | print "Copyright (C) 2005-2008, Ted Pedersen and Jason Michelizzi\n"; | ||
| 33 | print "This is free software, and you are welcome to redistribute it\n"; | ||
| 34 | print "under certain conditions. This software comes with ABSOLUTELY\n"; | ||
| 35 | print "NO WARRANTY. See the file GPL.txt for more information.\n"; | ||
| 36 | exit; | ||
| 37 | } | ||
| 38 | |||
| 39 | if ($help) { | ||
| 40 | showUsage("Long"); | ||
| 41 | exit; | ||
| 42 | } | ||
| 43 | |||
| 44 | my $target = shift; | ||
| 45 | my @context = @ARGV; | ||
| 46 | unless (defined $target and scalar @context) { | ||
| 47 | unless (defined $target) { | ||
| 48 | print STDERR "Error: no words were specified on command line!\n"; | ||
| 49 | } | ||
| 50 | else { | ||
| 51 | print STDERR "Error: no context words specified on command line!\n"; | ||
| 52 | } | ||
| 53 | showUsage(); | ||
| 54 | exit 1; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $qd = WordNet::QueryData->new; | ||
| 58 | |||
| 59 | # set up the options | ||
| 60 | my %options = (wordnet => $qd, | ||
| 61 | measure => $measure, | ||
| 62 | ); | ||
| 63 | $options{trace} = $trace if $trace; | ||
| 64 | $options{config} = $config if $config; | ||
| 65 | |||
| 66 | my $wts = WordNet::SenseRelate::WordToSet->new (%options); | ||
| 67 | |||
| 68 | my $result = $wts->disambiguate (target => $target, | ||
| 69 | context => [@context]); | ||
| 70 | |||
| 71 | for my $key (sort {$result->{$b} <=> $result->{$a}} keys %$result) { | ||
| 72 | print $key, ' : ', $result->{$key},' : ', | ||
| 73 | $qd -> querySense($key,'glos'), , "\n\n"; | ||
| 74 | } | ||
| 75 | |||
| 76 | if ($trace) { | ||
| 77 | my $tstr = $wts->getTrace (); | ||
| 78 | print "Traces:\n", $tstr, "\n"; | ||
| 79 | } | ||
| 80 | |||
| 81 | sub showUsage | ||
| 82 | { | ||
| 83 | my $long = shift; | ||
| 84 | print "Usage: wordtoset.pl targetword contextword1 [contextword2 ...]\n"; | ||
| 85 | print " [--type MEASURE] [--config FILE] [--trace LEVEL]\n"; | ||
| 86 | print " [--help] [--version]\n"; | ||
| 87 | |||
| 88 | if ($long) { | ||
| 89 | print " --type MEASURE WordNet::Similarity measure\n"; | ||
| 90 | print " --config FILE Configuration file for measure\n"; | ||
| 91 | print " --trace LEVEL Turn tracing on/off\n"; | ||
| 92 | print " --help Show this help message\n"; | ||
| 93 | print " --version Show version information\n"; | ||
| 94 | print "You may also run 'perldoc' on this script for more details\n"; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | __END__ |