/[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 560 by dpavlin, Sun Jul 2 14:40:32 2006 UTC revision 585 by dpavlin, Wed Jul 5 19:52:45 2006 UTC
# Line 8  use lib './lib'; Line 8  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.07;
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;
 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 236  while (my ($database, $db_config) = each Line 233  while (my ($database, $db_config) = each
233    
234                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
235                          module => $input_module,                          module => $input_module,
236                          code_page => $config->{webpac}->{webpac_encoding},                          encoding => $config->{webpac}->{webpac_encoding},
237                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
238                          offset => $offset,                          offset => $offset,
239                          lookup => $lookup,                          lookup_coderef => sub {
240                                    my $rec = shift || return;
241                                    $lookup->add( $rec );
242                            },
243                          recode => $input->{recode},                          recode => $input->{recode},
244                          stats => $stats,                          stats => $stats,
245                  );                  );
# Line 271  while (my ($database, $db_config) = each Line 271  while (my ($database, $db_config) = each
271    
272                          $log->info("Using $normalize_path for normalization...");                          $log->info("Using $normalize_path for normalization...");
273    
274                          my $marc_fh;                          my $marc = new WebPAC::Output::MARC(
275                          if (my $path = $normalize->{output}) {                                  path => $normalize->{output},
276                                  open($marc_fh, '>', $path) ||                                  lint => $marc_lint,
277                                          $log->logdie("can't open MARC output $path: $!");                                  dump => $marc_dump,
278                            ) if ($normalize->{output});
                                 $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n");  
                         }  
279    
280                          # reset position in database                          # reset position in database
281                          $input_db->seek(1);                          $input_db->seek(1);
# Line 319  while (my ($database, $db_config) = each Line 317  while (my ($database, $db_config) = each
317                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
318                                  ) if ($indexer && $ds);                                  ) if ($indexer && $ds);
319    
320                                  if ($marc_fh) {                                  if ($marc) {
321                                          my $marc = new MARC::Record;                                          my $i = 0;
                                         $marc->encoding( 'utf-8' );  
                                         my @marc_fields = WebPAC::Normalize::_get_marc_fields();  
                                         if (! @marc_fields) {  
                                                 $log->warn("MARC record $mfn is empty, skipping");  
                                         } else {  
                                                 $marc->add_fields( @marc_fields );  
   
                                                 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\n",  
                                                                 "Original imput row: ",dump($row), "\n",  
                                                                 "Normalized MARC row: ",dump(@marc_fields), "\n",  
                                                         );  
                                                 }  
322    
323                                                  print $marc_fh $marc->as_usmarc;                                          while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {
324                                                    $marc->add(
325                                                            id => $mfn . ( $i ? "/$i" : '' ),
326                                                            fields => $fields,
327                                                            leader => WebPAC::Normalize::marc_leader(),
328                                                            row => $row,
329                                                    );
330                                                    $i++;
331                                          }                                          }
332    
333                                            $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
334                                  }                                  }
335    
336                                  $total_rows++;                                  $total_rows++;
# Line 355  while (my ($database, $db_config) = each Line 339  while (my ($database, $db_config) = each
339                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
340    
341                          # close MARC file                          # close MARC file
342                          close($marc_fh) if ($marc_fh);                          $marc->finish if ($marc);
343    
344                  }                  }
345    

Legend:
Removed from v.560  
changed lines
  Added in v.585

  ViewVC Help
Powered by ViewVC 1.1.26