/[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 536 by dpavlin, Mon Jun 26 16:39:51 2006 UTC revision 540 by dpavlin, Thu Jun 29 15:29:41 2006 UTC
# Line 19  use Getopt::Long; Line 19  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;
23    
24  =head1 NAME  =head1 NAME
25    
# Line 220  while (my ($database, $db_config) = each Line 221  while (my ($database, $db_config) = each
221                          %{ $input },                          %{ $input },
222                  );                  );
223    
224                  my $rules;                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?
225                  my $normalize_path = $input->{normalize}->{path};                          @{ $input->{normalize} } : ( $input->{normalize} );
226    
227                  $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i );                  foreach my $normalize (@norm_array) {
228    
229                  my $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";                          my $rules;
230                            my $normalize_path = $normalize->{path} || $log->logdie("can't find normalize path in config");
231    
232                  foreach my $pos ( 0 ... $input_db->size ) {                          $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i );
233    
234                          my $row = $input_db->fetch || next;                          my $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";
235    
236                          my $mfn = $row->{'000'}->[0];                          $log->info("Using $normalize_path for normalization...");
237    
238                          if (! $mfn || $mfn !~ m#^\d+$#) {                          my $marc_fh;
239                                  $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");                          if (my $path = $normalize->{marc21}) {
240                                  $mfn = $pos;                                  open($marc_fh, '>', $path) ||
241                                  push @{ $row->{'000'} }, $pos;                                          $log->logdie("can't open MARC output $path: $!");
242    
243                                    $log->info("Creating MARC export file $path\n");
244                          }                          }
245    
246                            # reset position in database
247                            $input_db->seek(1);
248    
249                            foreach my $pos ( 0 ... $input_db->size ) {
250    
251                                    my $row = $input_db->fetch || next;
252    
253                                    my $mfn = $row->{'000'}->[0];
254    
255                          if ($validate) {                                  if (! $mfn || $mfn !~ m#^\d+$#) {
256                                  my @errors = $validate->validate_errors( $row );                                          $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");
257                                  $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);                                          $mfn = $pos;
258                                            push @{ $row->{'000'} }, $pos;
259                                    }
260    
261    
262                                    if ($validate) {
263                                            my @errors = $validate->validate_errors( $row );
264                                            $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
265                                    }
266    
267                                            
268                                    my $ds = WebPAC::Normalize::data_structure(
269                                            row => $row,
270                                            rules => $rules,
271                                            lookup => $lookup ? $lookup->lookup_hash : undef,
272                                    );
273    
274                                    $db->save_ds(
275                                            id => $mfn,
276                                            ds => $ds,
277                                            prefix => $input->{name},
278                                    ) if ($ds && !$stats);
279    
280                                    $indexer->add(
281                                            id => $input->{name} . "/" . $mfn,
282                                            ds => $ds,
283                                            type => $config->{$use_indexer}->{type},
284                                    ) if ($indexer && $ds);
285    
286                                    if ($marc_fh) {
287                                            my $marc = new MARC::Record;
288                                            $marc->add_fields( WebPAC::Normalize::_get_marc21_fields() );
289                                            print $marc_fh $marc->as_usmarc;
290                                    }
291    
292                                    $total_rows++;
293                          }                          }
294    
295                                                            $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
                         my $ds = WebPAC::Normalize::data_structure(  
                                 row => $row,  
                                 rules => $rules,  
                                 lookup => $lookup ? $lookup->lookup_hash : undef,  
                         );  
   
                         $db->save_ds(  
                                 id => $mfn,  
                                 ds => $ds,  
                                 prefix => $input->{name},  
                         ) if ($ds && !$stats);  
   
                         $indexer->add(  
                                 id => $input->{name} . "/" . $mfn,  
                                 ds => $ds,  
                                 type => $config->{$use_indexer}->{type},  
                         ) if ($indexer);  
296    
297                          $total_rows++;                          # close MARC file
298                  }                          close($marc_fh) if ($marc_fh);
299    
300                  $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                  }
301    
302          };          }
303    
304          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));
305    

Legend:
Removed from v.536  
changed lines
  Added in v.540

  ViewVC Help
Powered by ViewVC 1.1.26