Get a word’s definition(s), synonyms and hyponyms (related words) using perl and WordNet. The word must be specified as a command line argument, but the script could easily be modified to use an html parameter.
What you need:
-
Download and Install WordNet
-
Download and Install this Perl interface by Jason Rennie
-
Download this Perl Script:
-
usage: perl wordnet.pl word
#!/usr/bin/perl -w
use strict;
use warnings;
use WordNet::QueryData;my $word = $ARGV[0] or exit(usage());
my $wn = WordNet::QueryData->new;
my @senses = $wn->querySense("$word#n", “glos”);
my $i = 1;foreach my $sense(@senses) {
my $temp_sense = join(",", $wn->querySense($sense, “glos”));
my $temp_synset = join(",", $wn->querySense($sense, “syns”));
my $temp_hyponyms = join(",", $wn->querySense($sense, “hypo”));
$temp_synset =~ s/#\w#\d+//g;
$temp_hyponyms =~ s/#\w#\d+//g;
$temp_synset =~ s// /g;
$temp_hyponyms =~ s// /g;
print $i.". “.$temp_sense."\n”;
print “Synonyms: “.$temp_synset."\n”;
print “Related: “.$temp_hyponyms."\n”;
$i++;
}sub usage{
print “\n\n\nUsage: “.$0.” word\n\n\n\n”;
}