/[pgestraier]/trunk/data/indexer.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/data/indexer.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 82 by dpavlin, Thu May 25 18:46:49 2006 UTC revision 83 by dpavlin, Wed Jan 17 22:30:14 2007 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4  use Search::Estraier 0.06;  use Search::Estraier 0.06;
5    use parse_trivia;
6    
7  # score for words in title  # score for words in title
8  my $title_rank = 3;  my $title_rank = 3;
# Line 16  my $node = Search::Estraier::Node->new( Line 17  my $node = Search::Estraier::Node->new(
17          create => 1,          create => 1,
18  );  );
19    
20    my $nr = 1;
21    
22  my $header = 1;  parse_trivia($t, sub {
 my ($title, $year) = ('',undef);  
 my $in = 0;  
 my $trivia = '';  
 my @qv;  
   
 my ($all_years,$all_titles,$all_quotes);  
   
 sub qv {  
         my $t = shift || return;  
   
         sub qv_print {  
                 my $v = shift || return '';  
 #               $v =~ s/(.*)\s*,\s*(.+)/$2 $1/g;  
                 push @qv, $v;  
                 $all_quotes->{$v}++;  
                 return '';  
         }  
         $t =~ s#([_'"])([^_'"]+?)\1 \(qv\)#qv_print($2)#ge;  
 }  
   
 my $i = 0;  
   
 while(<$t>) {  
         if ($header && /^=====+/) {  
                 $header = 0;  
                 next;  
         }  
         next if $header;  
   
         if (/^#\s+(.*)\s*$/) {  
                 $title = $1;  
                 if ($title =~ m#^("*)(.*)\1\s*\((\d+)\)(:?\s*\(\w+\))*$#) {  
                         ($title, $year) = ($2,$3);  
                         $all_titles->{$title}++;  
                         $all_years->{$3}++;  
                 } else {  
                         $year = undef;  
                 }  
   
                 print "# $title ", ( $year ? "[$year]" : "" ), "\n";  
                 next;  
23    
24          } elsif (/^-\s(.*)\s*$/) {                  my $a = {@_};
                 $in = 1;  
                 $trivia = "$1\n";  
                 qv($1);  
         } elsif (/^\s\s(.*)\s*$/) {  
                 $trivia .= "$1\n";  
                 qv($1);  
         } elsif (/^$/ && $in) {  
                 $i++;  
                 print "$i ";  
25    
26                  # create a document object                  # create a document object
27                  my $doc = Search::Estraier::Document->new;                  my $doc = Search::Estraier::Document->new;
28    
29                  # add attributes to the document object                  # add attributes to the document object
30                  $doc->add_attr('@uri', "file://localhost/trivia/$i");                  $doc->add_attr('@uri', "file://localhost/trivia/$nr");
31    
32                  $doc->add_attr('@title', $title);                  $doc->add_attr('@title', $a->{title});
33                  $doc->add_hidden_text(                  $doc->add_hidden_text(
34                          ($title x $title_rank)                          (($a->{title} . ' ') x $title_rank)
35                  );                  );
36    
37                  $doc->add_attr('@size', length($trivia));                  $doc->add_attr('@size', length($a->{trivia}));
38    
39                  $doc->add_attr('year', $year) if ($year);                  $doc->add_attr('year', $a->{year}) if ($a->{year});
40                  foreach my $q (@qv) {                  foreach my $q ( $a->{qv} ) {
41                          $doc->add_attr('quote', $q);                          $doc->add_attr('quote', $q);
42                          $doc->add_hidden_text($q);                          $doc->add_hidden_text($q);
43                  }                  }
44    
45                  # add the body text to the document object                  # add the body text to the document object
46                  $doc->add_text($trivia);                  $doc->add_text($a->{trivia});
47    
48    
49                  # register the document object to the database                  # register the document object to the database
50                  $node->put_doc($doc);                  $node->put_doc($doc);
51    
52                  $trivia = '';  });
                 @qv = ();  
                 $in = 0;  
         } else {  
                 print "#$_\n";  
         }  
   
 #       last if ($i > 1000);    # XXX remove this!  
 }  
   
 sub dump_data($$) {  
         my ($name,$hash) = @_;  
   
         open(my $fh, "> $name") || die "can't open $name: $!";  
   
         foreach my $k (sort keys %{$hash}) {  
                 print $fh "$k\t",$hash->{$k},"\n";  
         }  
   
         close($fh);  
 }  
   
 #dump_data('titles.data', $all_titles);  
 #dump_data('quotes.data', $all_quotes);  
 #dump_data('years.data', $all_years);  
   

Legend:
Removed from v.82  
changed lines
  Added in v.83

  ViewVC Help
Powered by ViewVC 1.1.26