--- trunk/run.pl 2005/12/05 17:47:04 210 +++ trunk/run.pl 2005/12/18 21:06:46 286 @@ -7,12 +7,13 @@ use Data::Dumper; use lib './lib'; +use WebPAC::Common 0.02; use WebPAC::Lookup; -use WebPAC::Input::ISIS; +use WebPAC::Input::ISIS 0.02; use WebPAC::Store 0.03; use WebPAC::Normalize::XML; use WebPAC::Output::TT; -use WebPAC::Output::Estraier 0.02; +use WebPAC::Output::Estraier 0.05; use YAML qw/LoadFile/; use LWP::Simple; @@ -24,105 +25,145 @@ die "no databases in config file!\n" unless ($config->{databases}); +my $total_rows = 0; + while (my ($database, $db_config) = each %{ $config->{databases} }) { - my $type = lc($db_config->{input}->{type}); + my $log = _new WebPAC::Common()->_get_logger(); - die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); + # + # open Hyper Estraier database + # - my $abs_path = abs_path($0); - $abs_path =~ s#/[^/]*$#/#; + my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); + $est_config->{database} = $database; + + $log->info("using HyperEstraier URL $est_config->{masterurl}"); - my $lookup = new WebPAC::Lookup( - lookup_file => $db_config->{input}->{lookup}, + my $est = new WebPAC::Output::Estraier( + %{ $est_config }, ); - my $db_path = $config->{webpac}->{db_path} . '/' . $database; + # + # now WebPAC::Store + # + my $abs_path = abs_path($0); + $abs_path =~ s#/[^/]*$#/#; + my $db_path = $config->{webpac}->{db_path} . '/' . $database; - my $log = $lookup->_get_logger; $log->info("working on $database in $db_path"); - my $isis = new WebPAC::Input::ISIS( - code_page => $config->{webpac}->{webpac_encoding}, - limit_mfn => $db_config->{input}->{limit}, - ); - - my $maxmfn = $isis->open( - filename => $db_config->{input}->{path}, - code_page => $db_config->{input}->{encoding}, # database encoding - ); - - my $path = './db/'; - my $db = new WebPAC::Store( path => $db_path, + database => $database, + debug => 1, ); - my $n = new WebPAC::Normalize::XML( - # filter => { 'foo' => sub { shift } }, - db => $db, - lookup_regex => $lookup->regex, - lookup => $lookup, - ); - $n->open( - tag => $db_config->{normalize}->{tag}, - xml_file => $db_config->{normalize}->{path}, - ); + # + # now, iterate through input formats + # - my $out = new WebPAC::Output::TT( - include_path => $config->{webpac}->{template_path}, - filters => { foo => sub { shift } }, - ); + my @inputs; + if (ref($db_config->{input}) eq 'ARRAY') { + @inputs = @{ $db_config->{input} }; + } elsif ($db_config->{input}) { + push @inputs, $db_config->{input}; + } else { + $log->info("database $database doesn't have inputs defined"); + } - my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); - $est_config->{database} = $database; + my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; - $log->info("using HyperEstraier URL $est_config->{url}"); + foreach my $input (@inputs) { - my $est = new WebPAC::Output::Estraier( - %{ $est_config }, - ); + my $type = lc($input->{type}); - my $total_rows = 0; + die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); - for ( 0 ... $isis->size ) { + my $lookup = new WebPAC::Lookup( + lookup_file => $input->{lookup}, + ); - my $row = $isis->fetch || next; + my $input_module = $config->{webpac}->{inputs}->{$type}; - my $mfn = $row->{'000'}->[0] || die "can't find MFN"; + $log->info("working on input $input->{path} [$input->{type}] using $input_module"); - my $ds = $n->data_structure($row); + sub new_input { + my $name = shift; + my $args = shift; + new $name->($args); + } + + my $input = new_input($input_module,{ + code_page => $config->{webpac}->{webpac_encoding}, + limit_mfn => $input->{limit}, + lookup => $lookup, + }); + $log->logdie("can't create input using $input_module") unless ($input); + + my $maxmfn = $input->open( + path => $input->{path}, + code_page => $input->{encoding}, # database encoding + ); - # print STDERR Dumper($row, $ds); + my $n = new WebPAC::Normalize::XML( + # filter => { 'foo' => sub { shift } }, + db => $db, + lookup_regex => $lookup->regex, + lookup => $lookup, + prefix => $input->{name}, + ); - # 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; + my $normalize_path = $input->{normalize}->{path}; - $est->add( - id => $mfn, - ds => $ds, - type => $config->{hyperestraier}->{type}, - ); + if ($normalize_path =~ m/\.xml$/i) { + $n->open( + tag => $input->{normalize}->{tag}, + xml_file => $input->{normalize}->{path}, + ); + } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { + $n->open_yaml( + path => $normalize_path, + tag => $input->{normalize}->{tag}, + ); + } + + for ( 0 ... $input->size ) { + + my $row = $input->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++; + } }; $log->info("$total_rows records indexed"); + + # + # add Hyper Estraier links to other databases + # + if (ref($db_config->{links}) eq 'ARRAY') { + foreach my $link (@{ $db_config->{links} }) { + $log->info("adding link $database -> $link->{to} [$link->{credit}]"); + $est->add_link( + from => $database, + to => $link->{to}, + credit => $link->{credit}, + ); + } + } + }