#!/usr/local/bin/perl use strict; use warnings; use CGI; use DBI; my $query = new CGI; my $dbroot = "Jacy_2008-11-05"; my $cssdir = "/lextypedb"; my $cgidir = "/cgi-bin/lextypedb_tools"; my $charset = "utf-8"; my $version = "???"; if(-e "params"){ open(PARAM, "params"); while(){ chomp; (my $para, my $val) = split /=/;#/ if($para eq "dbroot"){ $dbroot = $val; }elsif($para eq "charset"){ $charset = $val; }elsif($para eq "cssdir"){ $cssdir = $val; }elsif($para eq "cgidir"){ $cgidir = $val; }elsif($para eq "version"){ $version = $val; } } close(PARAM); } #Receive the lextype param. my $type = $query->param("type"); my $dbname = $dbroot."/"."lt.db"; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", {AutoCommit => 0}); # # Retrieve the linguistic discussion # # Format and store in the string $linguisitcs # my $linguistics_table = "linguistics_tbl"; my $sth = $dbh->prepare( "select name,description,criteria,reference,todo from $linguistics_table where type=? limit 1" ); $sth->execute($type); my $linguistics =""; my $name; my $todo; if (my ($name, $description, $criteria, $reference, $todo) = $sth->fetchrow_array) { $linguistics = "
$description\n
$criteria\n
$reference\n";
}
#Retrieve example words, the number of types, and the number of tokens.
my $list_table = "list_tbl";
$sth = $dbh->prepare(
"select words,typefreq,tokenfreq from $list_table where lextype=?"
);
$sth->execute($type);
my @words;
my @word_ids;
my $typefreq;
my $tokenfreq;
while(my @row = $sth->fetchrow_array){
my @word_and_id_tmp = split /@/, $row[0];
my @examples_a = ();
foreach (@word_and_id_tmp){
my @word_and_id = split /:/, $_; #/
push(@word_ids, $word_and_id[0]);
push(@words, $word_and_id[1]);
}
$typefreq = $row[1];
$tokenfreq = $row[2];
}
my $words_s = join(", ", @words);
my @words_and_ids;
for(my $i=0; $i $mes";
foreach my $sid (@sids){
my $sentence = "";
$sth2->execute($sid);
while(my @row = $sth2->fetchrow_array){
if($row[0] eq $word_ids[$i]){
$sentence .= "
\n";
}
#Retrieve the TDL definition for the type.
my $tdl_definition;
my $types_table = "types_tbl";
$sth = $dbh->prepare(
"select parents,children,cat,val,cont,definition from $types_table where type=? limit 1"
);
$sth->execute($type);
my ($parents, $children, $cat, $val, $cont, $definition) = $sth->fetchrow_array;
my @supertype_a = split / /, $parents;
my @subtype_a = split / /, $children;
$definition =~ s/
/\n/g;
$definition =~ s/^/";
$tdl_definition .= "
\n";
# # Retrieve the Other Lexicon Mapping information for the lextype.
# my $otherlex_table = "otherlex_tbl";
# $sth = $dbh->prepare(
# "select lexicon, otherlextype, dice from $otherlex_table where lextype=\'$lextype\'"
# );
# $sth->execute;
# my %lexMap_tmp;
# while(my @row = $sth->fetchrow_array){
# $lexMap_tmp{$row[0]}{$row[1]} = $row[2];
# }
# my %lexMap;
# foreach my $lxcn (keys(%lexMap_tmp)){
# my @sorted_types = sort {
# $lexMap_tmp{$lxcn}{$b} <=> $lexMap_tmp{$lxcn}{$a}
# } keys %{$lexMap_tmp{$lxcn}};
# push(@{$lexMap{$lxcn}}, ($sorted_types[0], sprintf("%.3f",$lexMap_tmp{$lxcn}{$sorted_types[0]})));
# }
# # Retrieve the GOLD Mapping information for the lextype.
# my $gold;
# my $gold_table = "gold_tbl";
# $sth = $dbh->prepare(
# "select gold from $gold_table where lextype=\'$lextype\'"
# );
# $sth->execute;
# while(my @row = $sth->fetchrow_array){
# $gold = $row[0];
# }
# Message -------------------------------------
print $query->header(-type => 'text/html;charset='.$charset),
$query->start_html(-title=>$type.' (description)',
-style=>{'src' => $cssdir.'/lextypedb.css'});
print <<"HEADER";
\n";
$tdl_definition .= "Supertypes Head Category Valence Content Subtypes ";
$tdl_definition .= " \n";
$tdl_definition .= "";
for my $type (@supertype_a){
$tdl_definition .= "$type ";
}
$tdl_definition .= " ";
$tdl_definition .= "$cat ";
$tdl_definition .= "$val ";
$tdl_definition .= "$cont ";
$tdl_definition .= "";
for my $type (@subtype_a) {
$tdl_definition .= "$type ";
}
$tdl_definition .= " ";
$tdl_definition .= "$name $type ($words_s)
HEADER
if ($linguistics) {
print "Linguistic Discussion
\n$linguistics\n";
}
if ($typefreq > 0 || $tokenfreq > 0) {
print "Examples
";
if ($typefreq > 0) {
print "Example Words ($typefreq)
\n";
print $words_and_ids_s;
}
if ($tokenfreq > 0) {
print "Example Sentences ($tokenfreq)
";
print $sentences;
print "TDL Summary
TDL Definition
$tdl_definition
TODO
$todo
Lexical Type Database: ERROR