#!/usr/bin/perl -s our($registry,$n,$max,$corpus); # use CGI qw(:standard); use CQP; $corpus ||= 'parlamento-europeu-tmx-pt'; $n ||= '1 tu'; $max ||= '1000'; my $cqp = CQP->new("-b 10 -D ".uc($corpus)); my @corpora = map {s/^\s*//;ucfirst(lc($_))} $cqp->exec("show corpora;"); shift @corpora; ## first line is garbage $registry||= '/corpora/c1/registry'; my $paral=`grep ALIGNED $registry/$corpus`; ## is it a paralel corpus? $paral =~ s/ALIGNED\s*(\w+)/$1/; # print header; # print start_html(-title=>"Pesquisa no corpus '$corpus'"), # h1("Pesquisa no corpus '$corpus/$paral'"), hr, # start_form('POST',url), # start_form, # table(Tr(td(["procurar"," contexto", " no corpus ", "max"])), # Tr(td([textfield('k'), # popup_menu('n',["1 tu","7 words","20 words","1 s","1 p","0 words"]), # popup_menu('c',[@corpora]), # popup_menu('max',[20,200,1000,2000])]))), # end_form; # if(param()){ # my $pat = param("k"); my $pat=shift; $pat = doyourbest($pat); # print "
\n$pat\n
\n"; print "Pat=$pat\n\n"; $cqp->exec("set HardBoundary 15;"); $cqp->exec("set LeftContext $n ;"); $cqp->exec("set RightContext $n ;"); $cqp->exec("set LeftKWICDelim '' ;"); $cqp->exec("set RightKWICDelim '' ;"); $cqp->exec("show +$paral ;") if $paral; $cqp->exec("show -cpos ;"); # hide position in the corpus $cqp->exec("A = $pat"); print "Before cat A 0 $max\n"; @rs = $cqp->exec("cat A 0 $max;"); print "After cat A 0 $max\n"; print "número de ocorrências encontradas: ",b($cqp->exec("size A;")),"\n\n"; if($paral){ # print "\n"; while(@rs){ my $a=shift(@rs); my $b=shift(@rs); $b =~ s/-->$paral?://; #remove paralell corpus name # print Tr(td([$a,$b])); print "$a=$b\n"; } # print "
\n"; } # else{ print ol(li([@rs]));} else{ print join("\n",@rs);} # } # print hr,end_html; undef $q; sub doyourbest{ my $pat = shift; $pat =~ s/^\s*(\w+)\s*$/"$1";/; $pat =~ s/\b(alema|apos)\s*=\s*"(.*?)"/$1 contains "$2"/g; $pat } sub b{$_[0]} __END__