#!/usr/bin/perl -w use IO::Socket; use CGI; $CGI::DISABLE_UPLOADS = 0; # Here we connect to the AllWords server # If you want to use different port for communication, change it here. my $remote_host='127.0.0.1'; my $remote_port=32323; my $proto='tcp'; my $hostname; my $OK_CHARS='-a-zA-Z0-9_\'\n '; my ($kidpid, $handle, $line); my %options; my $status; my $filename; my $inputfile; my $stoplistfile; my $defstoplistfile; my $stoplistfilename; my $stoplist; my $contextfile; my $contextfilename; my $tracefilename; my $traceflag=0; my $defstop="off"; my $doc_base; my @tracelevel=(); BEGIN { # The carpout() function lets us modify the format of messages sent to # a filehandle (in this case STDERR) to include timestamps use CGI::Carp 'carpout'; carpout(*STDOUT); } my $cgi = CGI->new; # print the HTTP header print $cgi->header; $hostname=$ENV{'SERVER_NAME'}; my $usr_dir="user_data/". "user".time(); $inputfile="$usr_dir/"."input.txt"; $resultfilename="$usr_dir/"."results.txt"; $tracefilename="$usr_dir"."/trace.txt"; $status=system("mkdir $usr_dir"); if($status!=0) { writetoCGI("Can not create the user directory $usr_dir"); } $filename="$usr_dir/clientinput.txt"; $defstoplistfile="default-stoplist-raw.txt"; my $text = $cgi->param('text1') if defined $cgi->param('text1'); $contextfile=$cgi->param('contextfile') if defined $cgi->param('contextfile'); if ( (!$text) && (!$contextfile) ) { writetoCGI("\nPlease use back link to return to original page to enter your text\n"); print "
"; die "Could not complete the request as no text was entered. \n"; } my $windowSize = $cgi->param('winsize') if defined $cgi->param('winsize'); my $format = $cgi->param('format') if defined $cgi->param('format'); $options{wnformat} = 1 if $format eq 'wntagged'; my $scheme = $cgi->param('scheme') if defined $cgi->param('scheme'); if ($cgi->param('measure') =~ /lesk/) { $options{measure}= "lesk"; }elsif($cgi->param('measure') =~ /path/) { $options{measure}= "path"; }elsif($cgi->param('measure') =~ /wup/) { $options{measure}= "wup"; }elsif($cgi->param('measure') =~ /lch/) { $options{measure}= "lch"; }elsif($cgi->param('measure') =~ /hso/) { $options{measure}= "hso"; }elsif($cgi->param('measure') =~ /res/) { $options{measure}= "res"; }elsif($cgi->param('measure') =~ /lin/) { $options{measure}= "lin"; }elsif($cgi->param('measure') =~ /jcn/) { $options{measure}= "jcn"; }elsif($cgi->param('measure') =~ /vector/) { $options{measure}= "vector"; }elsif($cgi->param('measure') =~ /vector-pairs/) { $options{measure}= "vector-pairs"; } # Text was considered as a single line before. # Allowed \n character in $OK_CHARS to fix that. # Removing unwanted characters from the raw text. # If the text is tagged or wntagged, it is the user's responsibility # to clean text and remove unwanted characters if($text){ if ($format ne 'tagged' && $format ne 'wntagged') { $text = cleanLine($text); if ($text !~ /[a-zA-Z0-9]/) { writetoCGI("\nPlease use back link to return to original page to enter your text\n"); print ""; die "\nSorry. Your text should contain atleast one alphanumeric character\n"; } } $contextfilename="default-context-file.txt"; $context="$usr_dir/"."$contextfilename"; open CONTEXT,">","$context" or writetoCGI("Error writing contextfile."); print CONTEXT $text; close CONTEXT; } elsif($contextfile){ $contextfilename = getFileName($contextfile); $context="$usr_dir/"."$contextfilename"; open CONTEXT,">","$context" or writetoCGI("Error in uploading contextfile."); while(read($contextfile,$buffer,1024)){ if ($format ne 'tagged' && $format ne 'wntagged') { $text = cleanLine($text); if ($buffer !~ /[a-zA-Z0-9]/) { writetoCGI("\nPlease use back link to return to original page to enter your text\n"); print ""; die "\nSorry. Your text should contain atleast one alphanumeric character\n"; } } print CONTEXT $buffer; } close CONTEXT; } # If the user uploads his own stoplist as well as keep the default # stoplist option checked, the stoplist included by the user will # always override the default $stoplistfile=$cgi->param('stoplist'); if(!$stoplistfile) { $defstop=$cgi->param('defstoplist') if defined $cgi->param('defstoplist'); if ($defstop eq "on") { # $options{stoplist} = "./user_data/$defstoplistfile"; $options{stoplist} = "$defstoplistfile"; $status=system("cp ./user_data/$defstoplistfile $usr_dir/$defstoplistfile"); print "Error while copying the stoplist file." unless $status==0; } } else{ $stoplistfilename = getFileName($stoplistfile); $stoplist="$usr_dir/"."$stoplistfilename"; # $options{stoplist} = "$usr_dir/"."$stoplistfilename"; $options{stoplist} = "$stoplistfilename"; open STOPLIST,">","$stoplist" or writetoCGI("Error in uploading Testfile."); while(read($stoplistfile,$buffer,1024)) { print STOPLIST $buffer; } close STOPLIST; } $options{pairScore} = $cgi->param('pairscore') if defined $cgi->param('pairscore'); $options{contextScore} = $cgi->param('contextscore') if defined $cgi->param('contextscore'); #............................................................................. # # storing different tracelevels in an array so that it would be useful to show # traces of different levels. # #.................................................................................. $tracelevel[0] = defined $cgi->param('level1') ? $cgi->param('level1') : 0; $tracelevel[1] = defined $cgi->param('level2') ? $cgi->param('level2') : 0; $tracelevel[2] = defined $cgi->param('level4') ? $cgi->param('level4') : 0; $tracelevel[3] = defined $cgi->param('level8') ? $cgi->param('level8') : 0; $tracelevel[4] = defined $cgi->param('level16') ? $cgi->param('level16') : 0; $tracelevel[5] = defined $cgi->param('level32') ? $cgi->param('level32') : 0; foreach $trace (@tracelevel) { if( $trace > 0){ $options{trace}= defined $options{trace} ? ($options{trace} + $trace) : $trace; } } $options{forcepos} = $cgi->param('forcepos') if defined $cgi->param('forcepos'); $options{nocompoundify} = $cgi->param('nocompoundify') if defined $cgi->param('nocompoundify'); $options{usemono} = $cgi->param('usemono') if defined $cgi->param('usemono'); $options{backoff} = $cgi->param('backoff') if defined $cgi->param('backoff'); $doc_base=$ENV{'DOCUMENT_ROOT'}; open FH, '>', $filename or die "Cannot open $filename for writing: $!"; open IFH, '>', $inputfile or die "Cannot open $inputfile for writing: $!"; print FH "Could not convert $remote_host to an IP address: $!
\n"; die; }; my $paddr = sockaddr_in ($remote_port, $internet_addr); unless (connect (Server, $paddr)) { print "Cannot connect to server $remote_host:$remote_port ($!)
\n"; die; } select ((select (Server), $|=1)[0]); print "