--- trunk/run.pl 2006/09/25 14:06:49 706 +++ trunk/run.pl 2006/09/25 15:26:12 707 @@ -8,7 +8,7 @@ use WebPAC::Common 0.02; use WebPAC::Parser 0.04; -use WebPAC::Input 0.11; +use WebPAC::Input 0.13; use WebPAC::Store 0.03; use WebPAC::Normalize 0.11; use WebPAC::Output::TT; @@ -188,6 +188,15 @@ Proc::Queue::size($parallel); } +sub create_ds_config { + my ($db_config, $database, $input, $mfn) = @_; + my $c = dclone( $db_config ); + $c->{_} = $database || $log->logconfess("need database"); + $c->{_mfn} = $mfn || $log->logconfess("need mfn"); + $c->{input} = $input || $log->logconfess("need input"); + return $c; +} + while (my ($database, $db_config) = each %{ $config->databases }) { my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); @@ -318,33 +327,20 @@ my @lookups = $parser->have_lookup_create($database, $input); $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module", - @lookups ? "lookup ".join(", ", @lookups) : "" + @lookups ? " creating lookups: ".join(", ", @lookups) : "" ); -warn "lookups = ", dump( @lookups ); - if ($stats) { # disable modification of records if --stats is in use delete($input->{modify_records}); delete($input->{modify_file}); } - warn "parser->depends = ", dump( $parser->{depends} ); - warn "depends on: ", dump( $parser->depends($database, $input->{name}) ); - warn "lookup_create_rules = ", dump( $parser->lookup_create_rules($database, $input->{name}) ); - warn "parser->_lookup_create = ", dump( $parser->{_lookup_create} ); - - my $lookup; - my $input_db = new WebPAC::Input( module => $input_module, encoding => $config->webpac('webpac_encoding'), limit => $limit || $input->{limit}, offset => $offset, - lookup_coderef => sub { - my $rec = shift || return; - $lookup->add( $rec ); - }, recode => $input->{recode}, stats => $stats, modify_records => $input->{modify_records}, @@ -357,12 +353,42 @@ delete( $input->{lookup} ); } + my $lookup; + my $lookup_coderef; + + if (@lookups) { + + my $rules = $parser->lookup_create_rules($database, $input) || $log->logdie("no rules found for $database/$input"); + + $lookup_coderef = sub { + my $rec = shift || die "need rec!"; + my $mfn = $rec->{'000'}->[0] || die "need mfn in 000"; + + WebPAC::Normalize::data_structure( + row => $rec, + rules => $rules, + lookup => $lookup, + config => create_ds_config( $db_config, $database, $input, $mfn ), + ); + + warn "current lookup = ", dump($lookup) if ($lookup); + }; + + WebPAC::Normalize::_set_lookup( undef ); + + $log->debug("created lookup_coderef using:\n$rules"); + + }; + my $maxmfn = $input_db->open( path => $input->{path}, code_page => $input->{encoding}, # database encoding + lookup_coderef => $lookup_coderef, %{ $input }, ); + $log->debug("created following lookups: ", dump( WebPAC::Normalize::_get_lookup() ) ); + my $report_fh; if ($stats || $validate) { my $path = "out/report/" . $database . '-' . $input->{name} . '.txt'; @@ -427,22 +453,11 @@ } } - my $ds_config = dclone($db_config); - - # default values -> database key - $ds_config->{_} = $database; - - # current mfn - $ds_config->{_mfn} = $mfn; - - # attach current input - $ds_config->{input} = $input; - my $ds = WebPAC::Normalize::data_structure( row => $row, rules => $rules, lookup => $lookup ? $lookup->lookup_hash : undef, - config => $ds_config, + config => create_ds_config( $db_config, $database, $input, $mfn ), marc_encoding => 'utf-8', );