--- trunk/run.pl 2006/06/29 15:29:32 539 +++ trunk/run.pl 2006/06/30 20:43:18 552 @@ -19,6 +19,7 @@ use File::Path; use Time::HiRes qw/time/; use File::Slurp; +use MARC::Record 2.0; # need 2.0 for utf-8 encoding see marcpm.sf.net =head1 NAME @@ -62,6 +63,14 @@ turn on extra validation of imput records, see L +=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 + =back =cut @@ -75,6 +84,7 @@ my $only_filter; my $stats = 0; my $validate_path; +my ($marc_normalize, $marc_output); GetOptions( "limit=i" => \$limit, @@ -86,6 +96,8 @@ "debug" => \$debug, "stats" => \$stats, "validate=s" => \$validate_path, + "marc-normalize=s" => \$marc_normalize, + "marc-output=s" => \$marc_output, ); $config = LoadFile($config); @@ -110,6 +122,9 @@ $log->info("using $use_indexer indexing engine..."); } +# disable indexing when creating marc +$use_indexer = undef if ($marc_normalize); + my $total_rows = 0; my $start_t = time(); @@ -223,9 +238,15 @@ my @norm_array = ref($input->{normalize}) eq 'ARRAY' ? @{ $input->{normalize} } : ( $input->{normalize} ); + if ($marc_normalize) { + @norm_array = ( { + path => $marc_normalize, + output => $marc_output || 'out/marc/' . $database . '-' . $input->{name} . '.marc', + } ); + } + foreach my $normalize (@norm_array) { - my $rules; my $normalize_path = $normalize->{path} || $log->logdie("can't find normalize path in config"); $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i ); @@ -234,6 +255,14 @@ $log->info("Using $normalize_path for normalization..."); + my $marc_fh; + if (my $path = $normalize->{output}) { + open($marc_fh, '>', $path) || + $log->logdie("can't open MARC output $path: $!"); + + $log->info("Creating MARC export file $path\n"); + } + # reset position in database $input_db->seek(1); @@ -260,6 +289,7 @@ row => $row, rules => $rules, lookup => $lookup ? $lookup->lookup_hash : undef, + marc_encoding => 'utf-8', ); $db->save_ds( @@ -272,14 +302,24 @@ id => $input->{name} . "/" . $mfn, ds => $ds, type => $config->{$use_indexer}->{type}, - ) if ($indexer); + ) if ($indexer && $ds); + + if ($marc_fh) { + my $marc = new MARC::Record; + $marc->encoding( 'utf-8' ); + $marc->add_fields( WebPAC::Normalize::_get_marc_fields() ); + print $marc_fh $marc->as_usmarc; + } $total_rows++; } $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); - }; + # close MARC file + close($marc_fh) if ($marc_fh); + + } } @@ -295,7 +335,7 @@ # # add Hyper Estraier links to other databases # - if (ref($db_config->{links}) eq 'ARRAY') { + if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) { foreach my $link (@{ $db_config->{links} }) { if ($use_indexer eq 'hyperestraier') { $log->info("saving link $database -> $link->{to} [$link->{credit}]");