/[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 567 by dpavlin, Sun Jul 2 21:22:26 2006 UTC revision 595 by dpavlin, Mon Jul 10 10:16:11 2006 UTC
# Line 7  use File::Temp qw/tempdir/; Line 7  use File::Temp qw/tempdir/;
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 0.03;
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    use Storable qw/dclone/;
24    
25  =head1 NAME  =head1 NAME
26    
# Line 145  my $start_t = time(); Line 145  my $start_t = time();
145  my @links;  my @links;
146  my $indexer;  my $indexer;
147    
 my $lint = new MARC::Lint if ($marc_lint);  
   
148  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
149    
150          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 224  while (my ($database, $db_config) = each Line 222  while (my ($database, $db_config) = each
222    
223                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
224    
225                  my $lookup = new WebPAC::Lookup(                  my $lookup;
226                          lookup_file => $input->{lookup},                  if ($input->{lookup}) {
227                  ) if ($input->{lookup});                          $lookup = new WebPAC::Lookup(
228                                    lookup_file => $input->{lookup},
229                            );
230                            delete( $input->{lookup} );
231                    }
232    
233                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
234    
# Line 236  while (my ($database, $db_config) = each Line 238  while (my ($database, $db_config) = each
238    
239                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
240                          module => $input_module,                          module => $input_module,
241                          code_page => $config->{webpac}->{webpac_encoding},                          encoding => $config->{webpac}->{webpac_encoding},
242                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
243                          offset => $offset,                          offset => $offset,
244                          lookup => $lookup,                          lookup_coderef => sub {
245                                    my $rec = shift || return;
246                                    $lookup->add( $rec );
247                            },
248                          recode => $input->{recode},                          recode => $input->{recode},
249                          stats => $stats,                          stats => $stats,
250                  );                  );
# Line 271  while (my ($database, $db_config) = each Line 276  while (my ($database, $db_config) = each
276    
277                          $log->info("Using $normalize_path for normalization...");                          $log->info("Using $normalize_path for normalization...");
278    
279                          my $marc_fh;                          my $marc = new WebPAC::Output::MARC(
280                          if (my $path = $normalize->{output}) {                                  path => $normalize->{output},
281                                  open($marc_fh, '>', $path) ||                                  lint => $marc_lint,
282                                          $log->logdie("can't open MARC output $path: $!");                                  dump => $marc_dump,
283                            ) if ($normalize->{output});
                                 $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n");  
                         }  
284    
285                          # reset position in database                          # reset position in database
286                          $input_db->seek(1);                          $input_db->seek(1);
# Line 300  while (my ($database, $db_config) = each Line 303  while (my ($database, $db_config) = each
303                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
304                                  }                                  }
305    
306                                    my $ds_config = dclone($db_config);
307    
308                                    # default values -> database key
309                                    $ds_config->{_} = $database;
310    
311                                    # current mfn
312                                    $ds_config->{_mfn} = $mfn;
313    
314                                    # attach current input
315                                    $ds_config->{input} = $input;
316    
317                                  my $ds = WebPAC::Normalize::data_structure(                                  my $ds = WebPAC::Normalize::data_structure(
318                                          row => $row,                                          row => $row,
319                                          rules => $rules,                                          rules => $rules,
320                                          lookup => $lookup ? $lookup->lookup_hash : undef,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
321                                            config => $ds_config,
322                                          marc_encoding => 'utf-8',                                          marc_encoding => 'utf-8',
323                                  );                                  );
324    
# Line 319  while (my ($database, $db_config) = each Line 334  while (my ($database, $db_config) = each
334                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
335                                  ) if ($indexer && $ds);                                  ) if ($indexer && $ds);
336    
337                                  if ($marc_fh) {                                  if ($marc) {
338                                          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 );  
   
                                                 # 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\tleader:", $marc->leader(), "\n",  
                                                                 ">>>>> Original imput row:\n",dump($row), "\n",  
                                                                 ">>>>> Normalized MARC row:\n",dump(@marc_fields), "\n",  
                                                                 ">>>>> MARC lint warnings:\n",$err,"\n"  
                                                         ) if ($err);  
                                                 }  
   
                                                 if ($marc_dump) {  
                                                         $log->info("MARC record on MFN $mfn\tleader:", $marc->leader(), "\n",  
                                                                 ">>>>> Original imput row:\n",dump($row), "\n",  
                                                                 ">>>>> Normalized MARC row:\n",dump(@marc_fields), "\n",  
                                                         );  
                                                 }  
339    
340                                                  print $marc_fh $marc->as_usmarc;                                          while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {
341                                                    $marc->add(
342                                                            id => $mfn . ( $i ? "/$i" : '' ),
343                                                            fields => $fields,
344                                                            leader => WebPAC::Normalize::marc_leader(),
345                                                            row => $row,
346                                                    );
347                                                    $i++;
348                                          }                                          }
349    
350                                            $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
351                                  }                                  }
352    
353                                  $total_rows++;                                  $total_rows++;
# Line 368  while (my ($database, $db_config) = each Line 356  while (my ($database, $db_config) = each
356                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
357    
358                          # close MARC file                          # close MARC file
359                          close($marc_fh) if ($marc_fh);                          $marc->finish if ($marc);
360    
361                  }                  }
362    

Legend:
Removed from v.567  
changed lines
  Added in v.595

  ViewVC Help
Powered by ViewVC 1.1.26