#!/usr/bin/perl -T # # a script for viewing just one word. # loren jan wilson, sometime in 2003 use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DBI; use Reviews; $CGI::POST_MAX=1024 * 15; # max 20K posts $CGI::DISABLE_UPLOADS = 1; # no uploads $ENV{PATH} = ""; my $q = new CGI; print $q->header(-expires=>'now'); print $q->start_html(); #my $begin_time = time(); my $dbh = make_db_handle; my $id = $q->param('id') || 100; $id =~ s/[^\d]//g; $id = substr($id, 0, 10); my $word_id = $id; my $word = $q->param('word'); $word =~ s/[^A-Za-z-]//g; $word = substr($word, 0, 30); if ($word) { $word_id = dbquery($dbh, qq/ SELECT word.id FROM word WHERE word LIKE "$word" /); if (! $word_id) { print qq/"$word" not found in database./; exit; } } # get word and print it at the top my $word = dbquery($dbh, qq/ SELECT word FROM word WHERE id = $word_id /); print "

$word

\n"; # get positive and negative rating numbers my $positive_rating = dbquery($dbh,qq/ SELECT value FROM configuration WHERE variable like "positive_rating" /); my $negative_rating = dbquery($dbh,qq/ SELECT value FROM configuration WHERE variable like "negative_rating" /); # get information for this word my @fields = qw(tot pos neu neg pwr nwr avg art aut score); my $selectstring = join(",", @fields); my $values = dbquery($dbh, qq/ SELECT $selectstring FROM statistics,wordscore WHERE statistics.word_id = $word_id AND statistics.word_id = wordscore.word_id /); if ($values) { print qq/tot: $$values[0] (total number of occurrences of this word)
\n/; print qq/pos: $$values[1] (occurrences of this word in positive articles [rating > $positive_rating])
\n/; print qq/neu: $$values[2] (occurrences of this word in neutral articles [$negative_rating <= rating <= $positive_rating])
\n/; print qq/neg: $$values[3] (occurrences of this word in negative articles [rating < $negative_rating])
\n/; print "pwr: $$values[4] (positive word ratio [pos/tot])
\n"; print "nwr: $$values[5] (negative word ratio [neg/tot])
\n"; print qq/avg: $$values[6] (average rating of articles containing this word)
\n/; print qq/art: $$values[7] (number of articles containing this word)
\n/; print qq/aut: $$values[8] (number of authors who have used this word)
\n/; print qq/wordscore: $$values[9] ((avg - average avg) * tot)
\n/; print "

"; print "\n"; } else { print "There are too few occurrences of this word in the database to calculate useful statistics.

"; } print qq%See sentences which use this word: KWIC (Key Word In Context)
\n%; print qq%See other words which appear in the same sentence as this word: coex (coexistence)
%; print qq%See words which appear close to this word: close (phrase coexistence)%; # print a quick form... print $q->start_form, "Choose a particular word: ", $q->textfield(-name=>'word', -default=>'', -override=>1), $q->submit(-name=>"Submit"); #my $end_time = time(); #my $time_elapsed = $end_time - $begin_time; #print "\nquery time: $time_elapsed seconds\n"; print $q->end_html();