153 |
|
|
154 |
my $config = new WebPAC::Config( path => $config_path ); |
my $config = new WebPAC::Config( path => $config_path ); |
155 |
|
|
156 |
|
WebPAC::Normalize::_debug( $debug - 1 ) if $debug > 1; |
157 |
|
|
158 |
#print "config = ",dump($config) if ($debug); |
#print "config = ",dump($config) if ($debug); |
159 |
|
|
160 |
die "no databases in config file!\n" unless ($config->databases); |
die "no databases in config file!\n" unless ($config->databases); |
193 |
|
|
194 |
# parse normalize files and create source files for lookup and normalization |
# parse normalize files and create source files for lookup and normalization |
195 |
|
|
196 |
my $parser = new WebPAC::Parser( config => $config ); |
my ($only_database,$only_input) = split(m#/#, $only_filter) if $only_filter; |
197 |
|
|
198 |
|
my $parser = new WebPAC::Parser( |
199 |
|
config => $config, |
200 |
|
only_database => $only_database, |
201 |
|
only_input => $only_input, |
202 |
|
); |
203 |
|
|
204 |
my $total_rows = 0; |
my $total_rows = 0; |
205 |
my $start_t = time(); |
my $start_t = time(); |
223 |
foreach my $database ( sort keys %{ $config->databases } ) { |
foreach my $database ( sort keys %{ $config->databases } ) { |
224 |
my $db_config = $config->databases->{$database}; |
my $db_config = $config->databases->{$database}; |
225 |
|
|
|
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
|
226 |
next if ($only_database && $database !~ m/$only_database/i); |
next if ($only_database && $database !~ m/$only_database/i); |
227 |
|
|
228 |
if ($parallel) { |
if ($parallel) { |
328 |
|
|
329 |
# add database to arugemnts for output filter |
# add database to arugemnts for output filter |
330 |
$output->{database} = $database; |
$output->{database} = $database; |
331 |
|
$output->{clean} = $clean; |
332 |
|
|
333 |
$log->debug("calling $module->new(",dump( $output ),")"); |
$log->debug("calling $module->new(",dump( $output ),")"); |
334 |
my $out = new $module->new( $output ); |
my $out = new $module->new( $output ); |
335 |
$out->init; |
if ( $out->init ) { |
336 |
|
push @output_modules, $out; |
337 |
push @output_modules, $out; |
} else { |
338 |
|
$log->warn("SKIPPED $module"); |
339 |
|
} |
340 |
} |
} |
341 |
|
|
342 |
|
|
357 |
|
|
358 |
my $type = lc($input->{type}); |
my $type = lc($input->{type}); |
359 |
|
|
360 |
die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs'))); |
# FIXME check if input module exists |
361 |
|
my $input_module = $input->{module}; |
362 |
|
|
363 |
my $input_module = $config->webpac('inputs')->{$type}; |
if ( ! $input_module ) { |
364 |
|
if ( grep(/$type/, $config->webpac('inputs')) ) { |
365 |
|
$input_module = $config->webpac('inputs')->{$type}; |
366 |
|
} else { |
367 |
|
$log->logdie("I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!" ); |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
my @lookups = $parser->have_lookup_create($database, $input); |
my @lookups = $parser->have_lookup_create($database, $input); |
372 |
|
|
373 |
$log->info("working on input '$input_name' in $input->{path} [type: $input->{type}] using $input_module", |
$log->info("working on $database/$input_name with $input_module on $input->{path}", |
374 |
@lookups ? " creating lookups: ".join(", ", @lookups) : "" |
@lookups ? " creating lookups: ".join(", ", @lookups) : "" |
375 |
); |
); |
376 |
|
|
490 |
); |
); |
491 |
} |
} |
492 |
|
|
493 |
my $rules = $parser->normalize_rules($database,$input_name) || $log->logdie("no normalize rules found for $database/$input_name"); |
my $rules = $parser->normalize_rules($database,$input_name); |
494 |
|
$log->logwarn("no normalize rules for $database/$input_name") unless $rules; |
495 |
|
|
496 |
$log->debug("parsed normalize rules:\n$rules"); |
$log->debug("parsed normalize rules:\n$rules"); |
497 |
|
|
498 |
# reset position in database |
# reset position in database |
562 |
next; # validation doesn't create any output |
next; # validation doesn't create any output |
563 |
} |
} |
564 |
|
|
565 |
if ( my $ds = WebPAC::Normalize::data_structure( |
if ($rules) { |
566 |
row => $row, |
|
567 |
rules => $rules, |
my $ds = WebPAC::Normalize::data_structure( |
568 |
lookup => $lookup_hash, |
row => $row, |
569 |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
rules => $rules, |
570 |
marc_encoding => 'utf-8', |
lookup => $lookup_hash, |
571 |
load_row_coderef => sub { |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
572 |
my ($database,$input,$mfn) = @_; |
marc_encoding => 'utf-8', |
573 |
return $store->load_row( |
load_row_coderef => sub { |
574 |
|
my ($database,$input,$mfn) = @_; |
575 |
|
#warn "### load_row($database,$input,$mfn) from data_structure\n"; |
576 |
|
return $store->load_row( |
577 |
|
database => $database, |
578 |
|
input => $input, |
579 |
|
id => $mfn, |
580 |
|
); |
581 |
|
}, |
582 |
|
); |
583 |
|
|
584 |
|
$log->debug("ds = ", sub { dump($ds) }); |
585 |
|
|
586 |
|
if ( $ds ) { |
587 |
|
|
588 |
|
$store->save_ds( |
589 |
database => $database, |
database => $database, |
590 |
input => $input, |
input => $input_name, |
591 |
id => $mfn, |
id => $mfn, |
592 |
); |
ds => $ds, |
593 |
}, |
) if !$stats; |
|
) ) { # if |
|
594 |
|
|
595 |
$log->debug("ds = ", sub { dump($ds) }); |
$indexer->add( |
596 |
|
id => "${input_name}/${mfn}", |
597 |
|
ds => $ds, |
598 |
|
type => $config->get($indexer_config)->{type}, |
599 |
|
) if $indexer; |
600 |
|
|
601 |
$store->save_ds( |
foreach my $out ( @output_modules ) { |
602 |
database => $database, |
$out->add( $mfn, $ds ) if $out->can('add'); |
|
input => $input_name, |
|
|
id => $mfn, |
|
|
ds => $ds, |
|
|
) if !$stats; |
|
|
|
|
|
$indexer->add( |
|
|
id => "${input_name}/${mfn}", |
|
|
ds => $ds, |
|
|
type => $config->get($indexer_config)->{type}, |
|
|
) if $indexer; |
|
|
|
|
|
if ($marc) { |
|
|
my $i = 0; |
|
|
|
|
|
while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) { |
|
|
$marc->add( |
|
|
id => $mfn . ( $i ? "/$i" : '' ), |
|
|
fields => $fields, |
|
|
leader => WebPAC::Normalize::_get_marc_leader(), |
|
|
row => $row, |
|
|
); |
|
|
$i++; |
|
603 |
} |
} |
604 |
|
|
605 |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
} else { |
606 |
|
$log->warn("record $pos didn't produce any output after normalization rules!") unless $marc; |
607 |
} |
} |
608 |
|
} |
609 |
|
|
610 |
foreach my $out ( @output_modules ) { |
if ($marc) { |
611 |
$out->add( $mfn, $ds ) if $out->can('add'); |
my $i = 0; |
612 |
|
|
613 |
|
while (my $fields = WebPAC::Normalize::MARC::_get_marc_fields( fetch_next => 1 ) ) { |
614 |
|
$marc->add( |
615 |
|
id => $mfn . ( $i ? "/$i" : '' ), |
616 |
|
fields => $fields, |
617 |
|
leader => WebPAC::Normalize::MARC::_get_marc_leader(), |
618 |
|
row => $row, |
619 |
|
); |
620 |
|
$i++; |
621 |
} |
} |
622 |
|
|
623 |
} else { |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
|
$log->warn("record $pos didn't produce any output after normalization rules!"); |
|
624 |
} |
} |
625 |
|
|
626 |
} |
} |