#!/usr/bin/perl -T # # 2003-1129 # class.pl : prints each class, a description, the words, and links to # coexistence.pl and words.pl # # part of the pitchfork reviews project # loren jan wilson # use strict; use CGI qw(:standard -nosticky); 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 $dbh = make_db_handle; # first argument: sort order. # second argument: display only: (all, positive, negative, total) my $sort = $q->param('sort') || "positivity"; $sort = substr($sort, 0, 30); $sort =~ s/[^A-Za-z,]//g; $sort = lc($sort); $sort =~ s/,/, /g; $sort =~ s/desc/ desc/g; my $order = $q->param('order'); if (! $order) { if ($sort eq "total") { $order = "tot DESC"; } elsif ($sort eq "positivity") { $order = "pwr DESC"; } elsif ($sort eq "negativity") { $order = "nwr DESC"; } else { $order = $sort } } my $display = $q->param('display') || "all"; $display = substr($display, 0, 30); $display =~ s/[^A-Za-z,]//g; $display = lc($display); my $display_line = ""; ($display_line = "AND pwr > 0.54") if ($display eq "positive"); ($display_line = "AND nwr > 0.30") if ($display eq "negative"); ($display_line = "AND tot > 1000") if ($display eq "frequent"); # print first line print $q->h3("word classes"); # print a form for the sort order and words to include. print( $q->start_form(-method=>"GET"), "sort order for words:", $q->popup_menu(-name=>'sort', -values=>['positivity', 'negativity', 'total']), " display only these words:", $q->popup_menu(-name=>'display', -values=>['all', 'positive', 'negative', 'frequent']), " ",$q->submit(-value=>'Submit'), $q->end_form, "\n"); # print total number of words we're about to look at my $total_words; my $total_words = dbquery($dbh, qq/ SELECT count(word.id) FROM word_class,word,statistics WHERE word_class.word_id = word.id AND statistics.word_id = word.id $display_line ORDER BY $order /); print "

total number of words displayed: $total_words

"; # get classes my $classes = dbquery($dbh, qq/ SELECT id, name, description FROM class ORDER BY id /); # get words for each class and print them foreach my $class (@$classes) { my $class_id = $$class[0]; my $class_name = $$class[1]; my $class_desc = $$class[2]; print("$class_name - $class_desc", "

\n"); my $words = dbquery($dbh, qq/ SELECT word.id, word FROM word_class,word,statistics WHERE word_class.class_id = $class_id AND word_class.word_id = word.id AND statistics.word_id = word.id $display_line ORDER BY $order /); # construct the links to concordance.pl for each word my $word_id_list; my $length = 0; my $word_total = 0; foreach my $word_array (@$words) { next unless ref $word_array; $word_total++; my $word_id = $$word_array[0]; my $word = $$word_array[1]; # word wrap before we print this word... $length += length($word) + 1; if ($length > 70) { print "
\n"; $length = 0; } print qq%$word %; $word_id_list .= "$word_id+"; } print "

$word_total total words"; print "

\n"; $word_id_list =~ s/\+$//; # links to coexistence and statistics for this class print qq%- coexistence for $class_name (sorry, this takes a while)
%; print qq%- close coexistence for $class_name
%; print qq%- statistics for each word in $class_name%; print "

\n"; } print $q->end_html();