use strict; # This turns off output buffering, so output is immediate. $| = 1; # Load Wordnet use WordNet::QueryData; # Adjust location as needed my $wordnet = WordNet::QueryData->new("wordnet.db"); # This reads lines from STDIN. If there is no input, # it waits. while (my $input = <>) { # Remove the newline from the end chomp $input; # Here we have to think about a protocol. # I suggest something of the form command;arg1;arg2 my ($command, $arg1, $arg2) = split ';', $input; my @results; # Dispatch based on command if ($command eq 'quit') { exit; } elsif ($command eq 'word') { # Do a WordNet queryWord @results = $wordnet->queryWord($arg1, $arg2); } elsif ($command eq 'sense') { @results = $wordnet->querySense($arg1, $arg2); } else { die "Unknown command $command"; } # OK, send the results back out over STDOUT my $line = join ',', @results; print $line . "\n"; } #### perl.exe wordnet-ipc.pl