Minor (mostly notes to myself)
[pazpar2-moved-to-github.git] / heikki / queries / process3.pl
1 #!/usr/bin/perl -w
2 # Analyzing DBC's example queries
3 # Step 3: Eliminate search terms
4 # Assumes x3 is the result of process2.pl
5 # Result should be sorted and passed to the next step
6
7
8 open F, "x3" or die "could not open x3: $!\n";
9
10 my $linecount = 0;
11 my %counts;
12 while ( <F> ) {
13     next if /^#/;
14     chomp();
15     $linecount ++;
16     #last if ($linecount >10);
17     my ( $hits, $query) = split (';');
18     $query =~ s/^ +//;
19     $query =~ s/ +$//;
20     #print "$_ : '$query'\n";
21     my $nq = "";
22     for my $t ( split(' ',$query) ) {
23         #print "  '$t'\n";
24         if ( $t ne "og" && $t ne "eller" && $t ne "ikke" ) {
25             $t =~ s/[^ =]+/x/g;
26         }
27         $nq .= " " if ($nq);
28         $nq .= $t;
29     }
30     $counts{$nq} = 0 unless defined($counts{$nq});
31     $counts{$nq} += $hits;
32     print "$nq: $hits $counts{$nq}\n";
33 }
34 close F;
35
36 open OUT, ">x5" or die "could not open sort>x5 for writing: $!\n";
37 my $thisq = "";
38 my $sum = 0;
39 for my $q ( sort { $counts{$b} <=> $counts{$a} } keys(%counts) ) {
40     print "q='$q'  n=$counts{$q} \n";
41     print OUT "$counts{$q}; $q\n";
42 }
43 close OUT;