/[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

Annotation of /trunk/data/indexer.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (hide annotations)
Wed Jul 6 14:34:10 2005 UTC (18 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 2357 byte(s)
small cleanup

1 dpavlin 29 #!/usr/bin/perl -w
2    
3     use strict;
4     use HyperEstraier;
5    
6     # score for words in title
7     my $title_rank = 3;
8    
9     open(my $t, "gzip -cd trivia.list.gz |") || die "can't open trivia.list.gz: $!";
10    
11     # open the database
12     my $db = HyperEstraier::Database->new();
13     $db->open('casket', $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
14    
15    
16     my $header = 1;
17     my ($title, $year) = ('',undef);
18     my $in = 0;
19     my $trivia = '';
20     my @qv;
21    
22     my ($all_years,$all_titles,$all_quotes);
23    
24     sub qv {
25     my $t = shift || return;
26    
27     sub qv_print {
28     my $v = shift || return '';
29     # $v =~ s/(.*)\s*,\s*(.+)/$2 $1/g;
30     push @qv, $v;
31     $all_quotes->{$v}++;
32     return '';
33     }
34 dpavlin 30 $t =~ s#([_'"])([^_'"]+?)\1 \(qv\)#qv_print($2)#ge;
35 dpavlin 29 }
36    
37     my $i = 0;
38    
39     while(<$t>) {
40     if ($header && /^=====+/) {
41     $header = 0;
42     next;
43     }
44     next if $header;
45    
46     if (/^#\s+(.*)\s*$/) {
47     $title = $1;
48     if ($title =~ m#^("*)(.*)\1\s*\((\d+)\)(:?\s*\(\w+\))*$#) {
49 dpavlin 30 ($title, $year) = ($2,$3);
50     $all_titles->{$title}++;
51 dpavlin 29 $all_years->{$3}++;
52     } else {
53     $year = undef;
54     }
55    
56     print "# $title ", ( $year ? "[$year]" : "" ), "\n";
57     next;
58    
59     } elsif (/^-\s(.*)\s*$/) {
60     $in = 1;
61     $trivia = "$1\n";
62     qv($1);
63     } elsif (/^\s\s(.*)\s*$/) {
64     $trivia .= "$1\n";
65     qv($1);
66     } elsif (/^$/ && $in) {
67     $i++;
68     print "$i ";
69    
70     # create a document object
71     my $doc = HyperEstraier::Document->new;
72    
73     # add attributes to the document object
74     $doc->add_attr('@uri', "file://localhost/trivia/$i");
75 dpavlin 30
76 dpavlin 29 $doc->add_attr('@title', $title);
77 dpavlin 30 $doc->add_hidden_text(
78     ($title x $title_rank)
79     );
80    
81 dpavlin 29 $doc->add_attr('@size', length($trivia));
82    
83     $doc->add_attr('year', $year) if ($year);
84     foreach my $q (@qv) {
85     $doc->add_attr('quote', $q);
86     $doc->add_hidden_text($q);
87     }
88    
89     # add the body text to the document object
90     $doc->add_text($trivia);
91    
92    
93     # register the document object to the database
94     $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
95    
96     $trivia = '';
97     @qv = ();
98     $in = 0;
99     } else {
100     print "#$_\n";
101     }
102    
103     # last if ($i > 1000); # XXX remove this!
104     }
105    
106     sub dump_data($$) {
107     my ($name,$hash) = @_;
108    
109     open(my $fh, "> $name") || die "can't open $name: $!";
110    
111     foreach my $k (sort keys %{$hash}) {
112     print $fh "$k\t",$hash->{$k},"\n";
113     }
114    
115     close($fh);
116     }
117    
118     dump_data('titles.data', $all_titles);
119     dump_data('quotes.data', $all_quotes);
120     dump_data('years.data', $all_years);
121    
122     #print "\noptimizing...\n";
123     #$db->optimize(0);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26