13 |
use WebPAC::Normalize; |
use WebPAC::Normalize; |
14 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
15 |
use WebPAC::Validate; |
use WebPAC::Validate; |
16 |
|
use WebPAC::Output::MARC; |
17 |
use YAML qw/LoadFile/; |
use YAML qw/LoadFile/; |
18 |
use Getopt::Long; |
use Getopt::Long; |
19 |
use File::Path; |
use File::Path; |
20 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
21 |
use File::Slurp; |
use File::Slurp; |
|
use MARC::Record 2.0; # need 2.0 for utf-8 encoding see marcpm.sf.net |
|
|
use MARC::Lint; |
|
22 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
23 |
|
|
24 |
=head1 NAME |
=head1 NAME |
144 |
my @links; |
my @links; |
145 |
my $indexer; |
my $indexer; |
146 |
|
|
|
my $lint = new MARC::Lint if ($marc_lint); |
|
|
|
|
147 |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
148 |
|
|
149 |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
268 |
|
|
269 |
$log->info("Using $normalize_path for normalization..."); |
$log->info("Using $normalize_path for normalization..."); |
270 |
|
|
271 |
my $marc_fh; |
my $marc = new WebPAC::Output::MARC( |
272 |
if (my $path = $normalize->{output}) { |
path => $normalize->{output}, |
273 |
open($marc_fh, '>', $path) || |
lint => $marc_lint, |
274 |
$log->logdie("can't open MARC output $path: $!"); |
dump => $marc_dump, |
275 |
|
) if ($normalize->{output}); |
|
$log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n"); |
|
|
} |
|
276 |
|
|
277 |
# reset position in database |
# reset position in database |
278 |
$input_db->seek(1); |
$input_db->seek(1); |
314 |
type => $config->{$use_indexer}->{type}, |
type => $config->{$use_indexer}->{type}, |
315 |
) if ($indexer && $ds); |
) if ($indexer && $ds); |
316 |
|
|
317 |
if ($marc_fh) { |
$marc->add( |
318 |
my $marc = new MARC::Record; |
id => $mfn, |
319 |
$marc->encoding( 'utf-8' ); |
fields => [ WebPAC::Normalize::_get_marc_fields() ], |
320 |
my @marc_fields = WebPAC::Normalize::_get_marc_fields(); |
leader => WebPAC::Normalize::marc_leader(), |
321 |
if (! @marc_fields) { |
row => $row, |
322 |
$log->warn("MARC record $mfn is empty, skipping"); |
) if ($marc); |
|
} else { |
|
|
$marc->add_fields( @marc_fields ); |
|
|
|
|
|
# tweak leader |
|
|
if (my $new_l = WebPAC::Normalize::marc_leader()) { |
|
|
|
|
|
my $leader = $marc->leader; |
|
|
|
|
|
foreach my $o ( keys %$new_l ) { |
|
|
my $insert = $new_l->{$o}; |
|
|
$leader = substr($leader, 0, $o) . |
|
|
$insert . substr($leader, $o+length($insert)); |
|
|
} |
|
|
$marc->leader( $leader ); |
|
|
} |
|
|
|
|
|
if ($marc_lint) { |
|
|
$lint->check_record( $marc ); |
|
|
my $err = join( "\n", $lint->warnings ); |
|
|
$log->error("MARC lint detected warning on MFN $mfn\n", |
|
|
"Original imput row: ",dump($row), "\n", |
|
|
"Normalized MARC row: ",dump(@marc_fields), "\n", |
|
|
"MARC lint warnings: ",$err,"\n" |
|
|
) if ($err); |
|
|
} |
|
|
|
|
|
if ($marc_dump) { |
|
|
$log->info("MARC record on MFN $mfn\tleader:", $marc->leader(), "\n", |
|
|
"Original imput row: ",dump($row), "\n", |
|
|
"Normalized MARC row: ",dump(@marc_fields), "\n", |
|
|
); |
|
|
} |
|
|
|
|
|
print $marc_fh $marc->as_usmarc; |
|
|
} |
|
|
} |
|
323 |
|
|
324 |
$total_rows++; |
$total_rows++; |
325 |
} |
} |
327 |
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
328 |
|
|
329 |
# close MARC file |
# close MARC file |
330 |
close($marc_fh) if ($marc_fh); |
$marc->finish if ($marc); |
331 |
|
|
332 |
} |
} |
333 |
|
|