7 |
use lib './lib'; |
use lib './lib'; |
8 |
|
|
9 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
10 |
use WebPAC::Parser 0.04; |
use WebPAC::Parser 0.08; |
11 |
use WebPAC::Input 0.13; |
use WebPAC::Input 0.14; |
12 |
use WebPAC::Store 0.11; |
use WebPAC::Store 0.14; |
13 |
use WebPAC::Normalize 0.21; |
use WebPAC::Normalize 0.22; |
14 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
15 |
use WebPAC::Validate 0.06; |
use WebPAC::Validate 0.06; |
16 |
use WebPAC::Output::MARC; |
use WebPAC::Output::MARC; |
67 |
|
|
68 |
turn on extra validation of imput records, see L<WebPAC::Validation> |
turn on extra validation of imput records, see L<WebPAC::Validation> |
69 |
|
|
|
=item --marc-normalize conf/normalize/mapping.pl |
|
|
|
|
|
This option specifies normalisation file for MARC creation |
|
|
|
|
|
=item --marc-output out/marc/test.marc |
|
|
|
|
|
Optional path to output file |
|
|
|
|
70 |
=item --marc-lint |
=item --marc-lint |
71 |
|
|
72 |
By default turned on if C<--marc-normalize> is used. You can disable lint |
By default turned on if normalisation file has C<marc*> directives. You can disable lint |
73 |
messages with C<--no-marc-lint>. |
messages with C<--no-marc-lint>. |
74 |
|
|
75 |
=item --marc-dump |
=item --marc-dump |
102 |
my $only_filter; |
my $only_filter; |
103 |
my $stats = 0; |
my $stats = 0; |
104 |
my $validate_path; |
my $validate_path; |
|
my ($marc_normalize, $marc_output); |
|
105 |
my $marc_lint = 1; |
my $marc_lint = 1; |
106 |
my $marc_dump = 0; |
my $marc_dump = 0; |
107 |
my $parallel = 0; |
my $parallel = 0; |
120 |
"debug+" => \$debug, |
"debug+" => \$debug, |
121 |
"stats" => \$stats, |
"stats" => \$stats, |
122 |
"validate=s" => \$validate_path, |
"validate=s" => \$validate_path, |
|
"marc-normalize=s" => \$marc_normalize, |
|
|
"marc-output=s" => \$marc_output, |
|
123 |
"marc-lint!" => \$marc_lint, |
"marc-lint!" => \$marc_lint, |
124 |
"marc-dump!" => \$marc_dump, |
"marc-dump!" => \$marc_dump, |
125 |
"parallel=i" => \$parallel, |
"parallel=i" => \$parallel, |
160 |
$log->info("using $use_indexer indexing engine..."); |
$log->info("using $use_indexer indexing engine..."); |
161 |
} |
} |
162 |
|
|
|
# disable indexing when creating marc |
|
|
$use_indexer = undef if ($marc_normalize); |
|
|
|
|
163 |
# parse normalize files and create source files for lookup and normalization |
# parse normalize files and create source files for lookup and normalization |
164 |
|
|
165 |
my $parser = new WebPAC::Parser( config => $config ); |
my $parser = new WebPAC::Parser( config => $config ); |
198 |
} |
} |
199 |
|
|
200 |
my $indexer; |
my $indexer; |
201 |
if ($use_indexer) { |
if ($use_indexer && $parser->have_rules( 'search', $database )) { |
202 |
|
|
203 |
my $cfg_name = $use_indexer; |
my $cfg_name = $use_indexer; |
204 |
$cfg_name =~ s/\-.*$//; |
$cfg_name =~ s/\-.*$//; |
373 |
lookup_coderef => $lookup_coderef, |
lookup_coderef => $lookup_coderef, |
374 |
lookup => $lookup_jar, |
lookup => $lookup_jar, |
375 |
%{ $input }, |
%{ $input }, |
376 |
|
load_row => sub { |
377 |
|
my $a = shift; |
378 |
|
return $store->load_row( |
379 |
|
database => $database, |
380 |
|
input => $input_name, |
381 |
|
id => $a->{id}, |
382 |
|
); |
383 |
|
}, |
384 |
|
save_row => sub { |
385 |
|
my $a = shift; |
386 |
|
return $store->save_row( |
387 |
|
database => $database, |
388 |
|
input => $input_name, |
389 |
|
id => $a->{id}, |
390 |
|
row => $a->{row}, |
391 |
|
); |
392 |
|
}, |
393 |
|
|
394 |
); |
); |
395 |
|
|
396 |
my $lookup_data = WebPAC::Normalize::_get_lookup(); |
my $lookup_data = WebPAC::Normalize::_get_lookup(); |
397 |
|
|
398 |
if (defined( $lookup_data->{$database}->{$input_name} )) { |
if (defined( $lookup_data->{$database}->{$input_name} )) { |
399 |
$log->debug("created following lookups: ", dump( $lookup_data )); |
$log->debug("created following lookups: ", sub { dump( $lookup_data ) } ); |
400 |
|
|
401 |
foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) { |
foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) { |
402 |
$store->save_lookup( |
$store->save_lookup( |
419 |
} |
} |
420 |
|
|
421 |
my $marc; |
my $marc; |
422 |
if ($marc_normalize) { |
if ($parser->have_rules( 'marc', $database, $input_name )) { |
423 |
$marc = new WebPAC::Output::MARC( |
$marc = new WebPAC::Output::MARC( |
424 |
path => $marc_output || "out/marc/${database}-${input_name}.marc", |
path => "out/marc/${database}-${input_name}.marc", |
425 |
lint => $marc_lint, |
lint => $marc_lint, |
426 |
dump => $marc_dump, |
dump => $marc_dump, |
427 |
); |
); |
447 |
foreach my $db (keys %$depends) { |
foreach my $db (keys %$depends) { |
448 |
foreach my $i (keys %{$depends->{$db}}) { |
foreach my $i (keys %{$depends->{$db}}) { |
449 |
foreach my $k (keys %{$depends->{$db}->{$i}}) { |
foreach my $k (keys %{$depends->{$db}->{$i}}) { |
450 |
|
my $t = time(); |
451 |
$log->debug("loading lookup $db/$i"); |
$log->debug("loading lookup $db/$i"); |
452 |
$lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup( |
$lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup( |
453 |
database => $db, |
database => $db, |
454 |
input => $i, |
input => $i, |
455 |
key => $k, |
key => $k, |
456 |
); |
); |
457 |
|
$log->debug(sprintf("lookup $db/$i took %.2fs", time() - $t)); |
458 |
} |
} |
459 |
} |
} |
460 |
} |
} |
461 |
|
|
462 |
$log->debug("lookup_hash = ", dump( $lookup_hash )); |
$log->debug("lookup_hash = ", sub { dump( $lookup_hash ) }); |
463 |
} |
} |
464 |
|
|
465 |
|
|
477 |
|
|
478 |
|
|
479 |
if ($validate) { |
if ($validate) { |
480 |
if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) { |
if ( my $errors = $validate->validate_rec( $row, $input_db->dump ) ) { |
481 |
$log->error( "MFN $mfn validation error:\n", |
$log->error( "MFN $mfn validation error:\n", |
482 |
$validate->report_error( $errors ) |
$validate->report_error( $errors ) |
483 |
); |
); |
490 |
lookup => $lookup_hash, |
lookup => $lookup_hash, |
491 |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
492 |
marc_encoding => 'utf-8', |
marc_encoding => 'utf-8', |
493 |
load_ds_coderef => sub { |
load_row_coderef => sub { |
494 |
my ($database,$input,$mfn) = @_; |
my ($database,$input,$mfn) = @_; |
495 |
return $store->load_ds( |
return $store->load_row( |
496 |
database => $database, |
database => $database, |
497 |
input => $input, |
input => $input, |
498 |
id => $mfn, |
id => $mfn, |
500 |
}, |
}, |
501 |
); |
); |
502 |
|
|
503 |
|
$log->debug("ds = ", sub { dump($ds) }) if ($ds); |
504 |
|
|
505 |
$store->save_ds( |
$store->save_ds( |
506 |
database => $database, |
database => $database, |
507 |
input => $input_name, |
input => $input_name, |