#!/usr/local/bin/perl -w use strict; use CGI; my $query = new CGI; my $dbroot = "/var/www/html/lextypedb/db"; my $cssdir = "/lextypedb"; my $cgidir = "/cgi-bin/lextypedb_tools"; my $charset = "utf-8"; 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; } } open(PARAM, "params"); } ## only show $limit sentences my $limit = 50; #Receive params. my $lextype = $query->param("lextype"); my $wid = $query->param("wid"); my $orth = $query->param("orth"); #Retrieve all sentences that contain a word #whose lextype is $lextype and wid is $wid. use DBI; my $treebank_table = "treebank_tbl"; my $dbname = $dbroot."/"."lt.db"; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", {AutoCommit => 0}); #First, retrieve all the sentence ids. my $sth = $dbh->prepare( "select sid from $treebank_table where lextype=? and wordid=? limit $limit" ); $sth->execute($lextype,$wid); my @sid_a; while(my @row = $sth->fetchrow_array){ push(@sid_a, $row[0]); } #Next, retrieve the sentence itself for each sentence id. $sth = $dbh->prepare( "select wordid,orth from $treebank_table where sid=?" ); my $total = 0; my %all_sentences; foreach my $sid (@sid_a){ my @sentence = (); $sth->execute($sid); while(my @row = $sth->fetchrow_array){ my $orth = $row[1]; if ($row[0] eq $wid) { push @sentence, "$orth"; } else { push @sentence, $orth; } } my $string = join " ", @sentence; $string .= "\n"; $all_sentences{$sid} = $string; $total++; } # #Finally, prepare the output table that contains all sentences. my $out = ""; $out .= ""; foreach my $sid (keys %all_sentences){ $out .= ""; $out .= ""; } $out .= "
Sentencesex
$all_sentences{$sid}$sid
"; # Message ------------------------------------- print $query->header(-type => 'text/html;charset='.$charset), $query->start_html(-title=>$lextype.' (sentences)', -style=>{'src' => $cssdir.'/lextypedb.css'}); print <<"HTML_VIEW";
Word Search: 

$lextype (sentences)

First $total sentences containing "$orth" (max $limit).
$out

HTML_VIEW print $query->end_html; exit; # Error report ----------------------------------- sub error { my ($mes) = @_; print $query->header(-type => 'text/html;charset='.$charset), $query->start_html(-title=>'Creation Error', -style=>{'src' => $cssdir.'/lextypedb.css'}); print <<"HTML_VIEW";

Lexical Type Database: ERROR

$mes


HTML_VIEW print $query->end_html; exit; } __END__