--- trunk/run.pl 2005/12/05 17:46:57 209 +++ trunk/run.pl 2005/12/06 16:40:18 233 @@ -12,8 +12,9 @@ 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; @@ -21,94 +22,100 @@ print "config = ",Dumper($config); -my $type = lc($config->{input}->{type}); +die "no databases in config file!\n" unless ($config->{databases}); -die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); +my $total_rows = 0; + +while (my ($database, $db_config) = each %{ $config->{databases} }) { -my $abs_path = abs_path($0); -$abs_path =~ s#/[^/]*$#/#; + my $abs_path = abs_path($0); + $abs_path =~ s#/[^/]*$#/#; -my $lookup = new WebPAC::Lookup( - lookup_file => $config->{input}->{lookup}, -); + my $db_path = $config->{webpac}->{db_path} . '/' . $database; + my $db = new WebPAC::Store( + path => $db_path, + database => $database, + debug => 1, + ); + my $log = $db->_get_logger; + $log->info("working on $database in $db_path"); -my $isis = new WebPAC::Input::ISIS( - code_page => $config->{webpac}->{webpac_encoding}, - limit_mfn => $config->{input}->{limit}, -); + my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); + $est_config->{database} = $database; -my $maxmfn = $isis->open( - filename => $config->{input}->{path}, - code_page => $config->{input}->{encoding}, # database encoding -); + $log->info("using HyperEstraier URL $est_config->{masterurl}"); -my $path = './db/'; + my $est = new WebPAC::Output::Estraier( + %{ $est_config }, + ); -my $db = new WebPAC::Store( - path => $config->{webpac}->{db_path}, -); + # + # now, iterate through input formats + # -my $n = new WebPAC::Normalize::XML( -# filter => { 'foo' => sub { shift } }, - db => $db, - lookup_regex => $lookup->regex, - lookup => $lookup, -); + my @inputs; + if (ref($db_config->{input}) eq 'ARRAY') { + @inputs = @{ $db_config->{input} }; + } else { + push @inputs, $db_config->{input}; + } -$n->open( - tag => $config->{normalize}->{tag}, - xml_file => $config->{normalize}->{path}, -); + foreach my $input (@inputs) { -my $out = new WebPAC::Output::TT( - include_path => $config->{webpac}->{template_path}, - filters => { foo => sub { shift } }, -); + my $type = lc($input->{type}); -my $est = new WebPAC::Output::Estraier( - %{ $config->{hyperestraier} } -); + die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); -my $total_rows = 0; + my $lookup = new WebPAC::Lookup( + lookup_file => $input->{lookup}, + ); -for ( 0 ... $isis->size ) { + $log->info("working on input $input->{path} [$input->{type}]"); - my $row = $isis->fetch || next; + my $isis = new WebPAC::Input::ISIS( + code_page => $config->{webpac}->{webpac_encoding}, + limit_mfn => $input->{limit}, + ); - my $mfn = $row->{'000'}->[0] || die "can't find MFN"; + my $maxmfn = $isis->open( + filename => $input->{path}, + code_page => $input->{encoding}, # database encoding + ); - my $ds = $n->data_structure($row); + my $n = new WebPAC::Normalize::XML( + # filter => { 'foo' => sub { shift } }, + db => $db, + lookup_regex => $lookup->regex, + lookup => $lookup, + prefix => $input->{name}, + ); -# 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}, - ); + $n->open( + tag => $input->{normalize}->{tag}, + xml_file => $input->{normalize}->{path}, + ); + + 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); + + $est->add( + id => $input->{name} . "#" . $mfn, + ds => $ds, + type => $config->{hyperestraier}->{type}, + ); - $total_rows++; + $total_rows++; + } -}; + }; -my $log = $lookup->_get_logger; + $log->info("$total_rows records indexed"); +} -$log->info("$total_rows records indexed");