#!/usr/bin/perl use Pg; ###################### #build indices ##################### #1.build array with all the fields to get values in #2. extract unique values from each field #3. return a unique array for each field #4. build a linked index page, call a 'buildtrajanpage?key' for each value ##NB decide how to send several params after the ? @ind=qw(subjectkeywords toolkeywords sideofcolumn scenenumber drumnumber); foreach $i(@ind) { print "processing $i\n"; $fld=$i; &GETUNIQUE; } #get header and footer $header=`cat stndheader.txt`; $footer=`cat stndfooter.txt`; #print total num of matches $S_sk=@sk; print "$S_sk unique matches for subjectkeywords \n"; $S_tk=@tk; print "$S_tk unique matches for toolkeywords \n"; $S_sc=@sc; print "$S_sc unique matches for sideofcolumn \n"; $S_sn=@sn; print "$S_sn unique matches for scenenumber \n"; $S_dn=@dn; print "$S_dn unique matches for drumnumber \n"; $S_s=@s; print "$S_s unique matches for spiral \n"; ############################################# ##BUILD INDICES #1. subjectkeywords print "building subject keyword index...\n"; #$skout="Index organized by Subject Keyword\n"; $c=1; #@sortedsk= sort @sk; #foreach $elem(@sortedsk){ foreach $elem(@sk){ if (!($c==8)){$p="";}else{$p="

";$c=1;} $skout.= "   $elem$p\n"; $c++; } $c=1; #2. toolkeywords print "building tool keyword index...\n"; #$tkout="Index organized by Tool Keyword\n"; #@sortedtk= sort @tk; #foreach $elem(@sortedtk){ foreach $elem(@tk){ if (!($c==6)){$p="";}else{$p="

";$c=1;} $tkout.= "    $elem$p\n"; $c++ } $c=1; #3. sideofcolumn print "building side of column index...\n"; #$scout="Index organized by Side Of Column\n"; #@sortedsc= sort {$a <=> $b } @sc; #foreach $elem(@sortedsc){ foreach $elem(@sc){ if (!($c==12)){$p="";}else{$p="

";$c=1;} $scout.= "   $elem$p\n"; $c++; } $c=1; #4. scenenumber print "building scene number index...\n"; #$snout="Index organized by Scene Number\n"; #@sortedsn= sort {$a <=> $b } @sn; #foreach $elem(@sortedsn){ foreach $elem(@sn){ if (!($c==12)){$p="";}else{$p="

";$c=1;} $snout.= "   $elem$p\n"; $c++; } $c=1; #5. drumnumber print "building drum number index...\n"; #$dnout="Index organized by Drum Number\n"; #@sorteddn= sort {$a <=> $b } @dn; #foreach $elem(@sorteddn){ foreach $elem(@dn){ if (!($c==10)){$p="";}else{$p="

";$c=1;} $dnout.= "   $elem$p\n"; $c++; } $c=1; #6. spiral print "building spiral index...\n"; #$sout="Index organized by Spiral Number\n"; #@sorteds= sort {$a <=> $b } @s; #foreach $elem(@sorteds){ foreach $elem(@s){ if (!($c==10)){$p="";}else{$p="

";$c=1;} $sout.= "   $elem$p\n"; $c++; } #foreach $i(0..@s) { # print "Spiral=$s[$i] Drum=$dn[$i]\n"; #} #open a file and write the data to it open (F,">indices.html"); print F <\n \n Trajan's Column - Index\n \n \n

\n $header \n
\n
\n \n \n
Index organized by Subject Keyword
$skout
\n \n
Index organized by Tool Keyword\n
$tkout
\n \n
Index organized by Side Of Column\n
$scout
\n \n
Index organized by Scene Number\n
$snout
\n \n
Index organized by Drum Number\n
$dnout
\n \n
Index organized by Spiral Number\n
$sout
\n
\n
\n $footer
\n eof5 close (F); ######################################### sub GETUNIQUE { #build a hash, check the hash and then launch the appropriate sub handler #in that handler call PG %FIELDS = ( 'subjectkeywords' => \&FILTER_SK, 'toolkeywords' => \&FILTER_TK, 'scenenumber' => \&FILTER_SN, 'sideofcolumn' => \&FILTER_SC, 'drumnumber' => \&FILTER_DN ); #check the hash, the block checks for the key letter and fires off the sub assciated with it. if ($FIELDS{$fld}) {$FIELDS{$fld}->();} } #SUBJECT KEYWORDS sub FILTER_SK { &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; #$test=~s/_//g; if ($test && $test=~s/,/,/){ @testary=split ",",$test; foreach $elem(@testary){ if ($test && !($uniqueSK=~s/$elem/$elem/)){ $uniqueSK.="$elem,";} } } elsif ($test && !($uniqueSK=~s/$elem/$elem/)){ $uniqueSK.="$elem,"; } } } #now set the value we found to an array to check later #trim the trailing comma $uniqueSK=~s/,$//; @sk = split ",", $uniqueSK; } #TOOL KEYWORDS sub FILTER_TK { &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; #$test=~s/_//g; if ($test && $test=~s/,/,/){ @testary=split ",",$test; foreach $elem(@testary){ if ($test && !($uniqueTK=~s/$elem/$elem/)){ $uniqueTK.="$elem,"; print "$elem\n"; } } } elsif ($test && !($uniqueTK=~s/$elem/$elem/)){ $uniqueTK.="$elem,"; } } } #now set the value we found to an array to check later #trim the trailing comma $uniqueTK=~s/,$//; @tk = split ",", $uniqueTK; } #SCENE NUMBER, This may need some tlc to make sure to get all the numbers out sub FILTER_SN { &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; $test=~s/_//g; if ($test && ($test=~s/,/,/)){ @testcom=split ",", $test; foreach $elem(@testcom) { if (length $elem ==1 && !($single=~s/$elem/$elem/)){ $single.="$elem,"; }elsif (length $elem == 2 && !($double=~s/$elem/$elem/)){ $double.="$elem,"; }elsif (length $elem == 3 && !($tripple=~s/$elem/$elem/)){ $tripple.="$elem,"; }elsif (length $elem > 3 && !($other=~s/$elem/$elem/)){ $other.="$elem,"; } } }else { if ($test && (length $test ==1) && !($single=~s/$test/$test/)){ $single.="$test,"; }elsif ( $test && (length $test == 2) && !($double=~s/$test/$test/)){ $double.="$test,"; }elsif ( $test && (length $test == 3) && !($tripple=~s/$test/$test/)){ $tripple.="$test,"; }elsif ($test && (length $test > 3) && !($other=~s/$test/$test/)){ $other.="$test,"; } } } } $uniqueSN.="$single$double$tripple$other"; #now set the value we found to an array to check later #trim the trailing comma $uniqueSN=~s/,$//; @sn = split ",", $uniqueSN; } #SIDE OF COLUMN sub FILTER_SC { #no commas here &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; $test=~s/_//g; if($test && !($uniqueSC=~s/$test/$test/)){ $uniqueSC.="$test,";} } } #now set the value we found to an array to check later #trim the trailing comma $uniqueSC=~s/,$//; @sc = split ",", $uniqueSC; } #drum number #DRUM NUMBER, This may need some tlc to make sure to get all the numbers out sub FILTER_DN { &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; $test=~s/_//g; #separate spirals from drumnum @both=split ",", $test; $spirals.="$both[0],"; $drums.="$both[1],"; #print "SN=$both[0] : DN=$both[1]\n\n"; } } #now we have separated spirals and drums $spirals=~s/,$//; @spiralary= split ",", $spirals; $drums=~s/,$//; @drumary=split "," ,$drums; #show count $ts=@spiralary; print "\n$ts spirals\n"; $ts=@drumary; print "\n$ts drums\n"; #check for hyphenated entries foreach $test (@spiralary) { if ($test){ if (length $test ==1 && !($singleSN=~s/$test/$test/)){ $singleSN.="$test,"; }elsif (length $test == 2 && !($doubleSN=~s/$test/$test/)){ $doubleSN.="$test,"; }elsif (length $test == 3 && !($trippleSN=~s/$test/$test/)){ $trippleSN.="$test,"; }elsif ((length $test > 3) && !($otherSN=~s/$test/$test/)){ $otherSN.="$test,"; } } } $uniqueS=""; $uniqueS.="$singleSN$doubleSN$trippleSN$otherSN"; $uniqueS=~s/,$//; @s = split ",", $uniqueS; print "sprial unique array=$uniqueS\n"; #Drum numbers #check for hyphenated entries foreach $test (@drumary) { if ($test){ if (length $test ==1 && !($singleDN=~s/$test/$test/)){ $singleDN.="$test,"; }elsif (length $test == 2 && !($doubleDN=~s/$test/$test/)){ $doubleDN.="$test,"; }elsif (length $test == 3 && !($trippleDN=~s/$test/$test/)){ $trippleDN.="$test,"; }elsif ((length $test > 3) && !($otherDN=~s/$test/$test/)){ $otherDN.="$test,"; } } } $uniqueDN=""; $uniqueDN.="$singleDN$doubleDN$trippleDN$otherDN"; #now set the value we found to an array to check later #trim the trailing comma $uniqueDN=~s/,$//; @dn = split ",", $uniqueDN; #print "unique dn array=$otherDN\n"; } ############## sub old_FILTER_DN { #NB there are two pieces here, 1 spiral, 2 drum, just get drum here &CALLPG; #get the data from the array for $i ( 0 .. $#ary ) { for $j ( 0 .. $#{$ary[$i]} ) { $test= "$ary[$i][$j]"; #sometimes there is more than one word per field with commas $test=~s/ //g; $test=~s/_//g; @testary=split ",",$test; if ($test && !($uniqueDN=~s/$testary[1]/$testary[1]/)){ $uniqueDN.="$testary[1],";} #while we are here get spiral info too #check to see if it is <9 first if ($test && ($testary[0] < 9) && !($spiralA=~s/$testary[0]/$testary[0]/)){ $spiralA.="$testary[0],"; }elsif ($test && !($spiral=~s/$testary[0]/$testary[0]/)){ $spiral.="$testary[0],"; } } } #print "$uniqueDN\n"; #now set the value we found to an array to check later #trim the trailing comma #spirals $uniqueS="$spiralA$spiral"; $uniqueS=~s/,$//; @s=split ",", $uniqueS; #drumnumbers $uniqueDN=~s/,$//; @dn = split ",", $uniqueDN; } sub FILTER_KEYWORDS { #sometimes there is more than one word per field with commas $test=~s/ //g; $test=~s/_//g; if ($test && $test=~s/,/,/){ @testary=split ",",$test; foreach $elem(@testary){ #print $elem,"\n"; if (!($unique=~s/$elem/$elem/)){ $unique.="$elem,"; # print "mult unique -$elem\n"; } } }elsif ($test && !($unique=~s/$elem/$elem/)){ $unique.="$elem,"; #print "unique $elem\n"; } } sub CALLPG { #CALL PG AND GET LIST OF A FIELD $sql ="SELECT $fld from traj"; $conn = Pg::connectdb("dbname=trajan"); #execute the query Pg::doQuery($conn, $sql, \@ary); } exit;