r11519@llin: dpavlin | 2005-12-05 00:20:06 +0100
[webpac2] / run.pl
diff --git a/run.pl b/run.pl
index d0c4ae5..5a09b6b 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -9,90 +9,120 @@ use lib './lib';
 
 use WebPAC::Lookup;
 use WebPAC::Input::ISIS;
-use WebPAC::DB;
+use WebPAC::Store 0.03;
 use WebPAC::Normalize::XML;
 use WebPAC::Output::TT;
-use WebPAC::Output::Estraier;
+use WebPAC::Output::Estraier 0.02;
+use YAML qw/LoadFile/;
+use LWP::Simple;
 
 my $limit = shift @ARGV;
 
-my $abs_path = abs_path($0);
-$abs_path =~ s#/[^/]*$#/#;
+my $config = LoadFile('conf/config.yml');
 
-my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI';
+print "config = ",Dumper($config);
 
-my $lookup = new WebPAC::Lookup(
-       lookup_file => "$abs_path/conf/lookup/isis.pm",
-);
+die "no databases in config file!\n" unless ($config->{databases});
 
-my $isis = new WebPAC::Input::ISIS(
-       code_page => 'ISO-8859-2',      # application encoding
-       limit_mfn => $limit,
-);
+while (my ($database, $db_config) = each %{ $config->{databases} }) {
 
-my $maxmfn = $isis->open(
-       filename => $isis_file,
-       code_page => '852',             # database encoding
-);
+       my $type = lc($db_config->{input}->{type});
 
-my $path = './db/';
+       die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
 
-my $db = new WebPAC::DB(
-       path => $path,
-);
+       my $abs_path = abs_path($0);
+       $abs_path =~ s#/[^/]*$#/#;
 
-my $n = new WebPAC::Normalize::XML(
-#      filter => { 'foo' => sub { shift } },
-       db => $db,
-       lookup_regex => $lookup->regex,
-       lookup => $lookup,
-);
+       my $lookup = new WebPAC::Lookup(
+               lookup_file => $db_config->{input}->{lookup},
+       );
 
-$n->open(
-       tag => 'isis',
-       xml_file => "$abs_path/conf/normalize/isis_ffzg.xml",
-);
+       my $db_path = $config->{webpac}->{db_path} . '/' . $database;
 
-my $out = new WebPAC::Output::TT(
-       include_path => "$abs_path/conf/output/tt",
-       filters => { foo => sub { shift } },
-);
 
-my $est = new WebPAC::Output::Estraier(
-       url => 'http://localhost:1978/node/webpac2',
-       user => 'admin',
-       passwd => 'admin',
-       database => 'ps',
-);
+       my $log = $lookup->_get_logger;
+       $log->info("working on $database in $db_path");
 
-while (my $row = $isis->fetch) {
+       my $isis = new WebPAC::Input::ISIS(
+               code_page => $config->{webpac}->{webpac_encoding},
+               limit_mfn => $db_config->{input}->{limit},
+       );
 
-       my $mfn = $row->{'000'}->[0] || die "can't find MFN";
+       my $maxmfn = $isis->open(
+               filename => $db_config->{input}->{path},
+               code_page => $db_config->{input}->{encoding},   # database encoding
+       );
 
-       my $ds = $n->data_structure($row);
+       my $path = './db/';
 
-#      print STDERR Dumper($row, $ds);
+       my $db = new WebPAC::Store(
+               path => $db_path,
+       );
 
-       my $html = $out->apply(
-               template => 'html_ffzg.tt',
-               data => $ds,
+       my $n = new WebPAC::Normalize::XML(
+       #       filter => { 'foo' => sub { shift } },
+               db => $db,
+               lookup_regex => $lookup->regex,
+               lookup => $lookup,
        );
 
-       # create test output
+       $n->open(
+               tag => $db_config->{normalize}->{tag},
+               xml_file => $db_config->{normalize}->{path},
+       );
 
-       my $file = sprintf('out/%02d.html', $mfn );
-       open(my $fh, '>', $file) or die "can't open $file: $!";
-       print $fh $html;
-       close($fh);
+       my $out = new WebPAC::Output::TT(
+               include_path => $config->{webpac}->{template_path},
+               filters => { foo => sub { shift } },
+       );
 
-       $html =~ s#\s*[\n\r]+\s*##gs;
+       my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
+       $est_config->{database} = $database;
 
-#      print STDERR $html;
+       $log->info("using HyperEstraier URL $est_config->{url}");
 
-       $est->add(
-               id => $mfn,
-               ds => $ds,
-               type => 'search',
+       my $est = new WebPAC::Output::Estraier(
+               %{ $est_config },
        );
 
-};
+       my $total_rows = 0;
+
+       for ( 0 ... $isis->size ) {
+
+               my $row = $isis->fetch || next;
+
+               my $mfn = $row->{'000'}->[0] || die "can't find MFN";
+
+               my $ds = $n->data_structure($row);
+
+       #       print STDERR Dumper($row, $ds);
+
+       #       my $html = $out->apply(
+       #               template => 'html_ffzg.tt',
+       #               data => $ds,
+       #       );
+       #
+       #       # create test output
+       #
+       #       my $file = sprintf('out/%02d.html', $mfn );
+       #       open(my $fh, '>', $file) or die "can't open $file: $!";
+       #       print $fh $html;
+       #       close($fh);
+       #
+       #       $html =~ s#\s*[\n\r]+\s*##gs;
+       #
+       #       print STDERR $html;
+
+               $est->add(
+                       id => $mfn,
+                       ds => $ds,
+                       type => $config->{hyperestraier}->{type},
+               );
+
+               $total_rows++;
+
+       };
+
+       $log->info("$total_rows records indexed");
+}
+