#!/usr/local/bin/perl -wT use strict; use CGI; use Socket; my $remote_host = '127.0.0.1'; my $remote_port = 31134; my $doc_base = '../../similarity'; my $cgi = CGI->new; print $cgi->header; my $wps = $cgi->param ('wps') || 'undefined word'; print <<"EOB"; Gloss for $wps EOB unless ($wps =~ /[^#]+#[nvars]#\d+/) { print "

Error: bad input word: $wps

\n"; goto SHOW_END; } # connect to Similarity server socket (Server, PF_INET, SOCK_STREAM, getprotobyname ('tcp')); my $internet_addr = inet_aton ($remote_host) or do { print "

Could not convert $remote_host to an IP address: $!

\n"; goto SHOW_END; }; my $paddr = sockaddr_in ($remote_port, $internet_addr); unless (connect (Server, $paddr)) { print "

Cannot connect to server $remote_host:$remote_port ($!)

\n"; goto SHOW_END; } select ((select (Server), $|=1)[0]); print Server "g $wps\015\012"; print Server "\015\012"; while (my $line = ) { last if $line eq "\015\012"; my ($type, $str) = $line =~ m/^(\S+) (.+)/; if ($type eq 'g' or $type eq '1') { my ($wps, $gloss) = $str =~ m/([^#]+#[nvar]#\d+) (.*)/; print "
$wps
$gloss
\n"; } elsif ($type eq '!') { print "

$str

\n"; } else { print "

Error: odd message from server: ($type) $str

\n"; } } SHOW_END: close Server; print <<'EOH'; EOH __END__ =head1 NAME wps.cgi =head1 DESCRIPTION This script takes one parameter 'wps', which is a valid word#pos#sense string and produces a web page that displays the gloss of the synset to which that word sense belongs. =head1 AUTHORS Ted Pedersen, University of Minnesota Duluth tpederse at d.umn.edu Jason Michelizzi, University of Minnesota Duluth mich0212 at d.umn.edu =head1 BUGS None known. =head1 COPYRIGHT Copyright (c) 2005, Ted Pedersen and Jason Michelizzi This program is free software; you may redistribute and/or modify it under the terms of the GNU General Public License, version 2 or, at your option, any later version. =cut