4 |
|
|
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use File::Temp qw/tempdir/; |
use File::Temp qw/tempdir/; |
|
use Data::Dumper; |
|
7 |
use lib './lib'; |
use lib './lib'; |
8 |
|
|
9 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
10 |
use WebPAC::Lookup; |
use WebPAC::Lookup; |
11 |
use WebPAC::Input 0.03; |
use WebPAC::Input 0.03; |
12 |
use WebPAC::Store 0.03; |
use WebPAC::Store 0.03; |
13 |
use WebPAC::Normalize; |
use WebPAC::Normalize 0.11; |
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; |
22 |
use MARC::Record 2.0; # need 2.0 for utf-8 encoding see marcpm.sf.net |
use Data::Dump qw/dump/; |
23 |
|
|
24 |
=head1 NAME |
=head1 NAME |
25 |
|
|
71 |
|
|
72 |
Optional path to output file |
Optional path to output file |
73 |
|
|
74 |
|
=item --marc-lint |
75 |
|
|
76 |
|
By default turned on if C<--marc-normalize> is used. You can disable lint |
77 |
|
messages with C<--no-marc-lint>. |
78 |
|
|
79 |
|
=item --marc-dump |
80 |
|
|
81 |
|
Force dump or input and marc record for debugging. |
82 |
|
|
83 |
=back |
=back |
84 |
|
|
85 |
=cut |
=cut |
94 |
my $stats = 0; |
my $stats = 0; |
95 |
my $validate_path; |
my $validate_path; |
96 |
my ($marc_normalize, $marc_output); |
my ($marc_normalize, $marc_output); |
97 |
|
my $marc_lint = 1; |
98 |
|
my $marc_dump = 0; |
99 |
|
|
100 |
GetOptions( |
GetOptions( |
101 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
104 |
"one=s" => \$only_filter, |
"one=s" => \$only_filter, |
105 |
"only=s" => \$only_filter, |
"only=s" => \$only_filter, |
106 |
"config" => \$config, |
"config" => \$config, |
107 |
"debug" => \$debug, |
"debug+" => \$debug, |
108 |
"stats" => \$stats, |
"stats" => \$stats, |
109 |
"validate=s" => \$validate_path, |
"validate=s" => \$validate_path, |
110 |
"marc-normalize=s" => \$marc_normalize, |
"marc-normalize=s" => \$marc_normalize, |
111 |
"marc-output=s" => \$marc_output, |
"marc-output=s" => \$marc_output, |
112 |
|
"marc-lint!" => \$marc_lint, |
113 |
|
"marc-dump!" => \$marc_dump, |
114 |
); |
); |
115 |
|
|
116 |
$config = LoadFile($config); |
$config = LoadFile($config); |
117 |
|
|
118 |
print "config = ",Dumper($config) if ($debug); |
print "config = ",dump($config) if ($debug); |
119 |
|
|
120 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
121 |
|
|
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\n"); |
|
|
} |
|
276 |
|
|
277 |
# reset position in database |
# reset position in database |
278 |
$input_db->seek(1); |
$input_db->seek(1); |
295 |
$log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors); |
$log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors); |
296 |
} |
} |
297 |
|
|
|
|
|
298 |
my $ds = WebPAC::Normalize::data_structure( |
my $ds = WebPAC::Normalize::data_structure( |
299 |
row => $row, |
row => $row, |
300 |
rules => $rules, |
rules => $rules, |
314 |
type => $config->{$use_indexer}->{type}, |
type => $config->{$use_indexer}->{type}, |
315 |
) if ($indexer && $ds); |
) if ($indexer && $ds); |
316 |
|
|
317 |
if ($marc_fh) { |
if ($marc) { |
318 |
my $marc = new MARC::Record; |
my $i = 0; |
319 |
$marc->encoding( 'utf-8' ); |
|
320 |
$marc->add_fields( WebPAC::Normalize::_get_marc_fields() ); |
while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) { |
321 |
print $marc_fh $marc->as_usmarc; |
$marc->add( |
322 |
|
id => $mfn . ( $i ? "/$i" : '' ), |
323 |
|
fields => $fields, |
324 |
|
leader => WebPAC::Normalize::marc_leader(), |
325 |
|
row => $row, |
326 |
|
); |
327 |
|
$i++; |
328 |
|
} |
329 |
|
|
330 |
|
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
331 |
} |
} |
332 |
|
|
333 |
$total_rows++; |
$total_rows++; |
336 |
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
337 |
|
|
338 |
# close MARC file |
# close MARC file |
339 |
close($marc_fh) if ($marc_fh); |
$marc->finish if ($marc); |
340 |
|
|
341 |
} |
} |
342 |
|
|