/[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 730 by dpavlin, Tue Sep 26 12:42:49 2006 UTC revision 731 by dpavlin, Fri Sep 29 20:18:39 2006 UTC
# Line 10  use WebPAC::Common 0.02; Line 10  use WebPAC::Common 0.02;
10  use WebPAC::Parser 0.04;  use WebPAC::Parser 0.04;
11  use WebPAC::Input 0.13;  use WebPAC::Input 0.13;
12  use WebPAC::Store 0.11;  use WebPAC::Store 0.11;
13  use WebPAC::Normalize 0.11;  use WebPAC::Normalize 0.21;
14  use WebPAC::Output::TT;  use WebPAC::Output::TT;
15  use WebPAC::Validate 0.06;  use WebPAC::Validate 0.06;
16  use WebPAC::Output::MARC;  use WebPAC::Output::MARC;
# Line 354  while (my ($database, $db_config) = each Line 354  while (my ($database, $db_config) = each
354                          delete( $input->{lookup} );                          delete( $input->{lookup} );
355                  }                  }
356    
                 my $lookup;  
357                  my $lookup_coderef;                  my $lookup_coderef;
358    
359                  if (@lookups) {                  if (@lookups) {
# Line 367  while (my ($database, $db_config) = each Line 366  while (my ($database, $db_config) = each
366    
367                                  WebPAC::Normalize::data_structure(                                  WebPAC::Normalize::data_structure(
368                                          row => $rec,                                          row => $rec,
369                                          rules => $rules,                                          rules => "_debug(2); $rules _debug(0)",
                                         lookup => $lookup,  
370                                          config => create_ds_config( $db_config, $database, $input, $mfn ),                                          config => create_ds_config( $db_config, $database, $input, $mfn ),
371                                  );                                  );
372    
373                                  warn "current lookup = ", dump($lookup) if ($lookup);                                  warn "current lookup: ", dump(WebPAC::Normalize::_get_lookup());
374                          };                          };
375    
376                          WebPAC::Normalize::_set_lookup( undef );                          WebPAC::Normalize::_set_lookup( undef );
# Line 381  while (my ($database, $db_config) = each Line 379  while (my ($database, $db_config) = each
379    
380                  };                  };
381    
382                    my $lookup_jar;
383    
384                  my $maxmfn = $input_db->open(                  my $maxmfn = $input_db->open(
385                          path => $input->{path},                          path => $input->{path},
386                          code_page => $input->{encoding},        # database encoding                          code_page => $input->{encoding},        # database encoding
387                          lookup_coderef => $lookup_coderef,                          lookup_coderef => $lookup_coderef,
388                            lookup => $lookup_jar,
389                          %{ $input },                          %{ $input },
390                  );                  );
391    
# Line 413  while (my ($database, $db_config) = each Line 414  while (my ($database, $db_config) = each
414                          $log->info("Generating report file $path");                          $log->info("Generating report file $path");
415                  }                  }
416    
417                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?                  my $marc;
                         @{ $input->{normalize} } : ( $input->{normalize} );  
   
418                  if ($marc_normalize) {                  if ($marc_normalize) {
419                          @norm_array = ( {                          $marc = new WebPAC::Output::MARC(
420                                  path => $marc_normalize,                                  path => $marc_output || "out/marc/${database}-${input_name}.marc",
                                 output => $marc_output || "out/marc/${database}-${input_name}.marc",  
                         } );  
                 }  
   
                 foreach my $normalize (@norm_array) {  
   
                         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 );  
   
                         my $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";  
   
                         $log->info("Using $normalize_path for normalization...");  
   
                         my $marc = new WebPAC::Output::MARC(  
                                 path => $normalize->{output},  
421                                  lint => $marc_lint,                                  lint => $marc_lint,
422                                  dump => $marc_dump,                                  dump => $marc_dump,
423                          ) if ($normalize->{output});                          );
424                    }
                         # reset position in database  
                         $input_db->seek(1);  
   
                         # generate name of config key for indexer (strip everything after -)  
                         my $indexer_config = $use_indexer;  
                         $indexer_config =~ s/^(\w+)-?.*$/$1/g if ($indexer_config);  
   
                         foreach my $pos ( 0 ... $input_db->size ) {  
   
                                 my $row = $input_db->fetch || next;  
425    
426                                  my $mfn = $row->{'000'}->[0];                  my $rules = $parser->normalize_rules($database,$input_name) || $log->logdie("no normalize rules found for $database/$input_name");
427                    $log->debug("parsed normalize rules:\n$rules");
428    
429                                  if (! $mfn || $mfn !~ m#^\d+$#) {                  # reset position in database
430                                          $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");                  $input_db->seek(1);
                                         $mfn = $pos;  
                                         push @{ $row->{'000'} }, $pos;  
                                 }  
431    
432                    # generate name of config key for indexer (strip everything after -)
433                                  if ($validate) {                  my $indexer_config = $use_indexer;
434                                          if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {                  $indexer_config =~ s/^(\w+)-?.*$/$1/g if ($indexer_config);
435                                                  $log->error( "MFN $mfn validation error:\n",  
436                                                          $validate->report_error( $errors )                  my $lookup_hash;
437                    my $depends = $parser->depends($database,$input_name);
438            
439                    if ($depends) {
440                            $log->debug("$database/$input_name depends on: ", dump($depends)) if ($depends);
441                            $log->logdie("parser->depends didn't return HASH") unless (ref($depends) eq 'HASH');
442    
443                            foreach my $db (keys %$depends) {
444                                    foreach my $i (keys %{$depends->{$db}}) {
445                                            foreach my $k (keys %{$depends->{$db}->{$i}}) {
446                                                    $log->debug("loading lookup $db/$i");
447                                                    $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(
448                                                            database => $db,
449                                                            input => $i,
450                                                            key => $k,
451                                                  );                                                  );
452                                          }                                          }
453                                  }                                  }
454                            }
455    
456                                  my $ds = WebPAC::Normalize::data_structure(                          $log->debug("lookup_hash = ", dump( $lookup_hash ));
457                                          row => $row,                  }
                                         rules => $rules,  
                                         lookup => $lookup ? $lookup->lookup_hash : undef,  
                                         config => create_ds_config( $db_config, $database, $input, $mfn ),  
                                         marc_encoding => 'utf-8',  
                                 );  
458    
                                 $store->save_ds(  
                                         database => $database,  
                                         input => $input_name,  
                                         id => $mfn,  
                                         ds => $ds,  
                                 ) if ($ds && !$stats);  
   
                                 $indexer->add(  
                                         id => "${input_name}/${mfn}",  
                                         ds => $ds,  
                                         type => $config->get($indexer_config)->{type},  
                                 ) if ($indexer && $ds);  
   
                                 if ($marc) {  
                                         my $i = 0;  
   
                                         while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {  
                                                 $marc->add(  
                                                         id => $mfn . ( $i ? "/$i" : '' ),  
                                                         fields => $fields,  
                                                         leader => WebPAC::Normalize::marc_leader(),  
                                                         row => $row,  
                                                 );  
                                                 $i++;  
                                         }  
459    
460                                          $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                  foreach my $pos ( 0 ... $input_db->size ) {
461                                  }  
462                            my $row = $input_db->fetch || next;
463    
464                                  $total_rows++;                          my $mfn = $row->{'000'}->[0];
465    
466                            if (! $mfn || $mfn !~ m#^\d+$#) {
467                                    $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");
468                                    $mfn = $pos;
469                                    push @{ $row->{'000'} }, $pos;
470                          }                          }
471    
472    
473                          if ($validate) {                          if ($validate) {
474                                  my $errors = $validate->report;                                  if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {
475                                  if ($errors) {                                          $log->error( "MFN $mfn validation error:\n",
476                                          $log->info("validation errors:\n$errors\n" );                                                  $validate->report_error( $errors )
477                                          print $report_fh "$errors\n" if ($report_fh);                                          );
478                                  }                                  }
479                          }                          }
480    
481                          if ($stats) {                          my $ds = WebPAC::Normalize::data_structure(
482                                  my $s = $input_db->stats;                                  row => $row,
483                                  $log->info("statistics of fields usage:\n$s");                                  rules => $rules,
484                                  print $report_fh "Statistics of fields usage:\n$s" if ($report_fh);                                  lookup => $lookup_hash,
485                                    config => create_ds_config( $db_config, $database, $input, $mfn ),
486                                    marc_encoding => 'utf-8',
487                                    load_ds_coderef => sub {
488                                            my ($database,$input,$mfn) = @_;
489                                            return $store->load_ds(
490                                                    database => $database,
491                                                    input => $input,
492                                                    id => $mfn,
493                                            );
494                                    },
495                            );
496    
497                            $store->save_ds(
498                                    database => $database,
499                                    input => $input_name,
500                                    id => $mfn,
501                                    ds => $ds,
502                            ) if ($ds && !$stats);
503    
504                            $indexer->add(
505                                    id => "${input_name}/${mfn}",
506                                    ds => $ds,
507                                    type => $config->get($indexer_config)->{type},
508                            ) if ($indexer && $ds);
509    
510                            if ($marc) {
511                                    my $i = 0;
512    
513                                    while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {
514                                            $marc->add(
515                                                    id => $mfn . ( $i ? "/$i" : '' ),
516                                                    fields => $fields,
517                                                    leader => WebPAC::Normalize::marc_leader(),
518                                                    row => $row,
519                                            );
520                                            $i++;
521                                    }
522    
523                                    $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
524                          }                          }
525    
526                          # close MARC file                          $total_rows++;
527                          $marc->finish if ($marc);                  }
528    
529                          # close report                  if ($validate) {
530                          close($report_fh) if ($report_fh)                          my $errors = $validate->report;
531                            if ($errors) {
532                                    $log->info("validation errors:\n$errors\n" );
533                                    print $report_fh "$errors\n" if ($report_fh);
534                            }
535                  }                  }
536    
537                    if ($stats) {
538                            my $s = $input_db->stats;
539                            $log->info("statistics of fields usage:\n$s");
540                            print $report_fh "Statistics of fields usage:\n$s" if ($report_fh);
541                    }
542    
543                    # close MARC file
544                    $marc->finish if ($marc);
545    
546                    # close report
547                    close($report_fh) if ($report_fh)
548    
549          }          }
550    
551          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));

Legend:
Removed from v.730  
changed lines
  Added in v.731

  ViewVC Help
Powered by ViewVC 1.1.26