/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 576 by dpavlin, Mon Jul 3 22:12:13 2006 UTC revision 578 by dpavlin, Tue Jul 4 10:34:15 2006 UTC
# Line 13  use WebPAC::Store 0.03; Line 13  use WebPAC::Store 0.03;
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
# Line 145  my $start_t = time(); Line 144  my $start_t = time();
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);
# Line 271  while (my ($database, $db_config) = each Line 268  while (my ($database, $db_config) = each
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);
# Line 319  while (my ($database, $db_config) = each Line 314  while (my ($database, $db_config) = each
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:\n",dump($row), "\n",  
                                                                 ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump(@marc_fields), "\n",  
                                                                 "!!!!! MARC lint warnings:\n",$err,"\n"  
                                                         ) if ($err);  
                                                 }  
   
                                                 if ($marc_dump) {  
                                                         $log->info("MARC record on MFN $mfn\n",  
                                                                 "<<<<< Original imput row:\n",dump($row), "\n",  
                                                                 ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump(@marc_fields), "\n",  
                                                         );  
                                                 }  
   
                                                 print $marc_fh $marc->as_usmarc;  
                                         }  
                                 }  
323    
324                                  $total_rows++;                                  $total_rows++;
325                          }                          }
# Line 368  while (my ($database, $db_config) = each Line 327  while (my ($database, $db_config) = each
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    

Legend:
Removed from v.576  
changed lines
  Added in v.578

  ViewVC Help
Powered by ViewVC 1.1.26