#!/usr/bin/perl use strict; use CGI; use URI::Escape; ############################################################################## # # ############################################################################## if ($ARGV[0]=~/\.gz$/i) { open STDIN,"zcat $ARGV[0] |"; shift @ARGV; } ############################################################################## ## sub breakquery { my $sz=shift; my %res; $sz="\L$sz"; $sz=~s/\.[a-z]{2}\.//g; $sz=~s/\@[a-z]{2}.\d+//g; while ($sz=~s/[\"\']([^\"\']+?)[\"\']//) { $res{$1}++; } $sz=~s/\s{2}/ /g; $sz=~s/[\+\'\"\$\(\)]//g; if ($sz) { my @terms=split /[\s,]/,$sz; for my $t (@terms) { $t=~s/^\s+//; $t=~s/\s+$//; next if $t=~/^\s*$/ || $t=~/^..{0,1}$/ || $t!~/^[a-z0-9\-]+$/ || $t=~/^[0-9]+$/; $res{$t}++ unless grep /^$t$/,qw( and not or adj of the for with ); } } sort keys %res; } ############################################################################## while (<>) { next unless m{GET /netacgi/nph-brs\?([^\s]+)}; my $cgi=new CGI($1); next unless defined $cgi; my $db=$cgi->param("d"); next if $db=~/^\s*$/; $db="\U$db"; next if grep /^$db$/,qw( CHNH CHCA ); next if length($db)!=4; my $s4=$cgi->param("s4"); next unless defined $s4; next if $s4=~/^\s*$/; my @terms=breakquery $s4; print STDERR "\r"; printf STDERR "%.100s","$db ".join(" ",@terms); # $db $t }