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, |
153 |
|
|
154 |
|
|
155 |
my $use_indexer = $config->use_indexer; |
my $use_indexer = $config->use_indexer; |
156 |
|
$stats ||= $validate; |
157 |
if ($stats) { |
if ($stats) { |
158 |
$log->debug("option --stats disables update of indexing engine..."); |
$log->debug("disabled indexing for stats collection"); |
159 |
$use_indexer = undef; |
$use_indexer = undef; |
160 |
} else { |
} else { |
161 |
$log->info("using $use_indexer indexing engine..."); |
$log->info("using $use_indexer indexing engine..."); |
162 |
} |
} |
163 |
|
|
|
# disable indexing when creating marc |
|
|
$use_indexer = undef if ($marc_normalize); |
|
|
|
|
164 |
# parse normalize files and create source files for lookup and normalization |
# parse normalize files and create source files for lookup and normalization |
165 |
|
|
166 |
my $parser = new WebPAC::Parser( config => $config ); |
my $parser = new WebPAC::Parser( config => $config ); |
199 |
} |
} |
200 |
|
|
201 |
my $indexer; |
my $indexer; |
202 |
if ($use_indexer) { |
if ($use_indexer && $parser->have_rules( 'search', $database )) { |
203 |
|
|
204 |
my $cfg_name = $use_indexer; |
my $cfg_name = $use_indexer; |
205 |
$cfg_name =~ s/\-.*$//; |
$cfg_name =~ s/\-.*$//; |
374 |
lookup_coderef => $lookup_coderef, |
lookup_coderef => $lookup_coderef, |
375 |
lookup => $lookup_jar, |
lookup => $lookup_jar, |
376 |
%{ $input }, |
%{ $input }, |
377 |
|
load_row => sub { |
378 |
|
my $a = shift; |
379 |
|
return $store->load_row( |
380 |
|
database => $database, |
381 |
|
input => $input_name, |
382 |
|
id => $a->{id}, |
383 |
|
); |
384 |
|
}, |
385 |
|
save_row => sub { |
386 |
|
my $a = shift; |
387 |
|
return $store->save_row( |
388 |
|
database => $database, |
389 |
|
input => $input_name, |
390 |
|
id => $a->{id}, |
391 |
|
row => $a->{row}, |
392 |
|
); |
393 |
|
}, |
394 |
|
|
395 |
); |
); |
396 |
|
|
397 |
my $lookup_data = WebPAC::Normalize::_get_lookup(); |
my $lookup_data = WebPAC::Normalize::_get_lookup(); |
398 |
|
|
399 |
if (defined( $lookup_data->{$database}->{$input_name} )) { |
if (defined( $lookup_data->{$database}->{$input_name} )) { |
400 |
$log->debug("created following lookups: ", dump( $lookup_data )); |
$log->debug("created following lookups: ", sub { dump( $lookup_data ) } ); |
401 |
|
|
402 |
foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) { |
foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) { |
403 |
$store->save_lookup( |
$store->save_lookup( |
420 |
} |
} |
421 |
|
|
422 |
my $marc; |
my $marc; |
423 |
if ($marc_normalize) { |
if ($parser->have_rules( 'marc', $database, $input_name )) { |
424 |
$marc = new WebPAC::Output::MARC( |
$marc = new WebPAC::Output::MARC( |
425 |
path => $marc_output || "out/marc/${database}-${input_name}.marc", |
path => "out/marc/${database}-${input_name}.marc", |
426 |
lint => $marc_lint, |
lint => $marc_lint, |
427 |
dump => $marc_dump, |
dump => $marc_dump, |
428 |
); |
); |
448 |
foreach my $db (keys %$depends) { |
foreach my $db (keys %$depends) { |
449 |
foreach my $i (keys %{$depends->{$db}}) { |
foreach my $i (keys %{$depends->{$db}}) { |
450 |
foreach my $k (keys %{$depends->{$db}->{$i}}) { |
foreach my $k (keys %{$depends->{$db}->{$i}}) { |
451 |
|
my $t = time(); |
452 |
$log->debug("loading lookup $db/$i"); |
$log->debug("loading lookup $db/$i"); |
453 |
$lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup( |
$lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup( |
454 |
database => $db, |
database => $db, |
455 |
input => $i, |
input => $i, |
456 |
key => $k, |
key => $k, |
457 |
); |
); |
458 |
|
$log->debug(sprintf("lookup $db/$i took %.2fs", time() - $t)); |
459 |
} |
} |
460 |
} |
} |
461 |
} |
} |
462 |
|
|
463 |
$log->debug("lookup_hash = ", dump( $lookup_hash )); |
$log->debug("lookup_hash = ", sub { dump( $lookup_hash ) }); |
464 |
} |
} |
465 |
|
|
466 |
|
|
468 |
|
|
469 |
my $row = $input_db->fetch || next; |
my $row = $input_db->fetch || next; |
470 |
|
|
471 |
|
$total_rows++; |
472 |
|
|
473 |
my $mfn = $row->{'000'}->[0]; |
my $mfn = $row->{'000'}->[0]; |
474 |
|
|
475 |
if (! $mfn || $mfn !~ m#^\d+$#) { |
if (! $mfn || $mfn !~ m#^\d+$#) { |
480 |
|
|
481 |
|
|
482 |
if ($validate) { |
if ($validate) { |
483 |
if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) { |
if ( my $errors = $validate->validate_rec( $row, $input_db->dump ) ) { |
484 |
$log->error( "MFN $mfn validation error:\n", |
$log->error( "MFN $mfn validation error:\n", |
485 |
$validate->report_error( $errors ) |
$validate->report_error( $errors ) |
486 |
); |
); |
487 |
} |
} |
488 |
|
next; # validation doesn't create any output |
489 |
} |
} |
490 |
|
|
491 |
my $ds = WebPAC::Normalize::data_structure( |
my $ds = WebPAC::Normalize::data_structure( |
494 |
lookup => $lookup_hash, |
lookup => $lookup_hash, |
495 |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
config => create_ds_config( $db_config, $database, $input, $mfn ), |
496 |
marc_encoding => 'utf-8', |
marc_encoding => 'utf-8', |
497 |
load_ds_coderef => sub { |
load_row_coderef => sub { |
498 |
my ($database,$input,$mfn) = @_; |
my ($database,$input,$mfn) = @_; |
499 |
return $store->load_ds( |
return $store->load_row( |
500 |
database => $database, |
database => $database, |
501 |
input => $input, |
input => $input, |
502 |
id => $mfn, |
id => $mfn, |
504 |
}, |
}, |
505 |
); |
); |
506 |
|
|
507 |
|
$log->debug("ds = ", sub { dump($ds) }) if ($ds); |
508 |
|
|
509 |
$store->save_ds( |
$store->save_ds( |
510 |
database => $database, |
database => $database, |
511 |
input => $input_name, |
input => $input_name, |
534 |
|
|
535 |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
536 |
} |
} |
|
|
|
|
$total_rows++; |
|
537 |
} |
} |
538 |
|
|
539 |
if ($validate) { |
if ($validate) { |