/[webpac2]/trunk/run.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/run.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 268 - (hide annotations)
Fri Dec 16 21:09:42 2005 UTC (18 years, 4 months ago) by dpavlin
File MIME type: text/plain
File size: 3112 byte(s)
 r11742@llin:  dpavlin | 2005-12-17 01:26:41 +0100
 cleanup

1 dpavlin 74 #!/usr/bin/perl -w
2    
3     use strict;
4    
5     use Cwd qw/abs_path/;
6     use File::Temp qw/tempdir/;
7     use Data::Dumper;
8     use lib './lib';
9    
10 dpavlin 255 use WebPAC::Common 0.02;
11 dpavlin 74 use WebPAC::Lookup;
12     use WebPAC::Input::ISIS;
13 dpavlin 209 use WebPAC::Store 0.03;
14 dpavlin 74 use WebPAC::Normalize::XML;
15     use WebPAC::Output::TT;
16 dpavlin 255 use WebPAC::Output::Estraier 0.05;
17 dpavlin 141 use YAML qw/LoadFile/;
18 dpavlin 210 use LWP::Simple;
19 dpavlin 74
20 dpavlin 76 my $limit = shift @ARGV;
21    
22 dpavlin 141 my $config = LoadFile('conf/config.yml');
23    
24     print "config = ",Dumper($config);
25    
26 dpavlin 210 die "no databases in config file!\n" unless ($config->{databases});
27 dpavlin 141
28 dpavlin 213 my $total_rows = 0;
29    
30 dpavlin 210 while (my ($database, $db_config) = each %{ $config->{databases} }) {
31 dpavlin 141
32 dpavlin 255 my $log = _new WebPAC::Common()->_get_logger();
33    
34     #
35     # open Hyper Estraier database
36     #
37    
38     my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
39     $est_config->{database} = $database;
40    
41     $log->info("using HyperEstraier URL $est_config->{masterurl}");
42    
43     my $est = new WebPAC::Output::Estraier(
44     %{ $est_config },
45     );
46    
47     #
48     # now WebPAC::Store
49     #
50 dpavlin 210 my $abs_path = abs_path($0);
51     $abs_path =~ s#/[^/]*$#/#;
52 dpavlin 141
53 dpavlin 210 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
54 dpavlin 74
55 dpavlin 255 $log->info("working on $database in $db_path");
56    
57 dpavlin 210 my $db = new WebPAC::Store(
58     path => $db_path,
59 dpavlin 217 database => $database,
60 dpavlin 221 debug => 1,
61 dpavlin 210 );
62 dpavlin 74
63 dpavlin 233
64 dpavlin 213 #
65     # now, iterate through input formats
66     #
67 dpavlin 74
68 dpavlin 213 my @inputs;
69     if (ref($db_config->{input}) eq 'ARRAY') {
70     @inputs = @{ $db_config->{input} };
71 dpavlin 255 } elsif ($db_config->{input}) {
72     push @inputs, $db_config->{input};
73 dpavlin 213 } else {
74 dpavlin 255 $log->info("database $database doesn't have inputs defined");
75 dpavlin 213 }
76 dpavlin 74
77 dpavlin 213 foreach my $input (@inputs) {
78 dpavlin 233
79     my $type = lc($input->{type});
80    
81     die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
82    
83     my $lookup = new WebPAC::Lookup(
84     lookup_file => $input->{lookup},
85     );
86    
87 dpavlin 213 $log->info("working on input $input->{path} [$input->{type}]");
88 dpavlin 74
89 dpavlin 213 my $isis = new WebPAC::Input::ISIS(
90     code_page => $config->{webpac}->{webpac_encoding},
91     limit_mfn => $input->{limit},
92 dpavlin 251 lookup => $lookup,
93 dpavlin 213 );
94 dpavlin 113
95 dpavlin 213 my $maxmfn = $isis->open(
96     filename => $input->{path},
97     code_page => $input->{encoding}, # database encoding
98     );
99 dpavlin 113
100 dpavlin 213 my $n = new WebPAC::Normalize::XML(
101     # filter => { 'foo' => sub { shift } },
102     db => $db,
103     lookup_regex => $lookup->regex,
104     lookup => $lookup,
105 dpavlin 221 prefix => $input->{name},
106 dpavlin 213 );
107 dpavlin 113
108 dpavlin 213 $n->open(
109     tag => $input->{normalize}->{tag},
110     xml_file => $input->{normalize}->{path},
111 dpavlin 210 );
112    
113 dpavlin 213 for ( 0 ... $isis->size ) {
114 dpavlin 210
115 dpavlin 213 my $row = $isis->fetch || next;
116    
117     my $mfn = $row->{'000'}->[0] || die "can't find MFN";
118    
119     my $ds = $n->data_structure($row);
120    
121     $est->add(
122     id => $input->{name} . "#" . $mfn,
123     ds => $ds,
124     type => $config->{hyperestraier}->{type},
125     );
126    
127     $total_rows++;
128     }
129    
130 dpavlin 210 };
131    
132     $log->info("$total_rows records indexed");
133 dpavlin 255
134     #
135     # add Hyper Estraier links to other databases
136     #
137     if (ref($db_config->{links}) eq 'ARRAY') {
138     foreach my $link (@{ $db_config->{links} }) {
139     $log->info("adding link $database -> $link->{to} [$link->{credit}]");
140     $est->add_link(
141     from => $database,
142     to => $link->{to},
143     credit => $link->{credit},
144     );
145     }
146     }
147    
148 dpavlin 210 }
149    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26