/[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 736 by dpavlin, Thu Oct 5 12:57:51 2006 UTC revision 774 by dpavlin, Fri Nov 3 20:56:21 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::Parser 0.04;  use WebPAC::Parser 0.08;
11  use WebPAC::Input 0.13;  use WebPAC::Input 0.16;
12  use WebPAC::Store 0.11;  use WebPAC::Store 0.14;
13  use WebPAC::Normalize 0.22;  use WebPAC::Normalize 0.22;
14  use WebPAC::Output::TT;  use WebPAC::Output::TT;
15  use WebPAC::Validate 0.06;  use WebPAC::Validate 0.06;
# Line 67  and subfield usage for each input Line 67  and subfield usage for each input
67    
68  turn on extra validation of imput records, see L<WebPAC::Validation>  turn on extra validation of imput records, see L<WebPAC::Validation>
69    
 =item --marc-normalize conf/normalize/mapping.pl  
   
 This option specifies normalisation file for MARC creation  
   
 =item --marc-output out/marc/test.marc  
   
 Optional path to output file  
   
70  =item --marc-lint  =item --marc-lint
71    
72  By default turned on if C<--marc-normalize> is used. You can disable lint  By default turned on if normalisation file has C<marc*> directives. You can disable lint
73  messages with C<--no-marc-lint>.  messages with C<--no-marc-lint>.
74    
75  =item --marc-dump  =item --marc-dump
# Line 110  my $debug = 0; Line 102  my $debug = 0;
102  my $only_filter;  my $only_filter;
103  my $stats = 0;  my $stats = 0;
104  my $validate_path;  my $validate_path;
 my ($marc_normalize, $marc_output);  
105  my $marc_lint = 1;  my $marc_lint = 1;
106  my $marc_dump = 0;  my $marc_dump = 0;
107  my $parallel = 0;  my $parallel = 0;
# Line 129  GetOptions( Line 120  GetOptions(
120          "debug+" => \$debug,          "debug+" => \$debug,
121          "stats" => \$stats,          "stats" => \$stats,
122          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
         "marc-normalize=s" => \$marc_normalize,  
         "marc-output=s" => \$marc_output,  
123          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
124          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
125          "parallel=i" => \$parallel,          "parallel=i" => \$parallel,
# Line 164  $validate = new WebPAC::Validate( Line 153  $validate = new WebPAC::Validate(
153    
154    
155  my $use_indexer = $config->use_indexer;  my $use_indexer = $config->use_indexer;
156    $stats ||= $validate;
157  if ($stats) {  if ($stats) {
158          $log->debug("option --stats disables update of indexing engine...");          $log->debug("disabled indexing for stats collection");
159          $use_indexer = undef;          $use_indexer = undef;
160  } else {  } else {
161          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
162  }  }
163    
 # disable indexing when creating marc  
 $use_indexer = undef if ($marc_normalize);  
   
164  # parse normalize files and create source files for lookup and normalization  # parse normalize files and create source files for lookup and normalization
165    
166  my $parser = new WebPAC::Parser( config => $config );  my $parser = new WebPAC::Parser( config => $config );
# Line 212  while (my ($database, $db_config) = each Line 199  while (my ($database, $db_config) = each
199          }          }
200    
201          my $indexer;          my $indexer;
202          if ($use_indexer) {          if ($use_indexer && $parser->have_rules( 'search', $database )) {
203    
204                  my $cfg_name = $use_indexer;                  my $cfg_name = $use_indexer;
205                  $cfg_name =~ s/\-.*$//;                  $cfg_name =~ s/\-.*$//;
# Line 364  while (my ($database, $db_config) = each Line 351  while (my ($database, $db_config) = each
351                                  my $rec = shift || die "need rec!";                                  my $rec = shift || die "need rec!";
352                                  my $mfn = $rec->{'000'}->[0] || die "need mfn in 000";                                  my $mfn = $rec->{'000'}->[0] || die "need mfn in 000";
353    
                                 $store->save_row(  
                                         database => $database,  
                                         input => $input_name,  
                                         id => $mfn,  
                                         row => $rec,  
                                 );  
   
354                                  WebPAC::Normalize::data_structure(                                  WebPAC::Normalize::data_structure(
355                                          row => $rec,                                          row => $rec,
356                                          rules => $rules,                                          rules => $rules,
# Line 394  while (my ($database, $db_config) = each Line 374  while (my ($database, $db_config) = each
374                          lookup_coderef => $lookup_coderef,                          lookup_coderef => $lookup_coderef,
375                          lookup => $lookup_jar,                          lookup => $lookup_jar,
376                          %{ $input },                          %{ $input },
377                            load_row => sub {
378                                    my $a = shift;
379                                    return $store->load_row(
380                                            database => $database,
381                                            input => $input_name,
382                                            id => $a->{id},
383                                    );
384                            },
385                            save_row => sub {
386                                    my $a = shift;
387                                    return $store->save_row(
388                                            database => $database,
389                                            input => $input_name,
390                                            id => $a->{id},
391                                            row => $a->{row},
392                                    );
393                            },
394    
395                  );                  );
396    
397                  my $lookup_data = WebPAC::Normalize::_get_lookup();                  my $lookup_data = WebPAC::Normalize::_get_lookup();
398    
399                  if (defined( $lookup_data->{$database}->{$input_name} )) {                  if (defined( $lookup_data->{$database}->{$input_name} )) {
400                          $log->debug("created following lookups: ", dump( $lookup_data ));                          $log->debug("created following lookups: ", sub { dump( $lookup_data ) } );
401    
402                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {
403                                  $store->save_lookup(                                  $store->save_lookup(
# Line 422  while (my ($database, $db_config) = each Line 420  while (my ($database, $db_config) = each
420                  }                  }
421    
422                  my $marc;                  my $marc;
423                  if ($marc_normalize) {                  if ($parser->have_rules( 'marc', $database, $input_name )) {
424                          $marc = new WebPAC::Output::MARC(                          $marc = new WebPAC::Output::MARC(
425                                  path => $marc_output || "out/marc/${database}-${input_name}.marc",                                  path => "out/marc/${database}-${input_name}.marc",
426                                  lint => $marc_lint,                                  lint => $marc_lint,
427                                  dump => $marc_dump,                                  dump => $marc_dump,
428                          );                          );
# Line 450  while (my ($database, $db_config) = each Line 448  while (my ($database, $db_config) = each
448                          foreach my $db (keys %$depends) {                          foreach my $db (keys %$depends) {
449                                  foreach my $i (keys %{$depends->{$db}}) {                                  foreach my $i (keys %{$depends->{$db}}) {
450                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {
451                                                    my $t = time();
452                                                  $log->debug("loading lookup $db/$i");                                                  $log->debug("loading lookup $db/$i");
453                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(
454                                                          database => $db,                                                          database => $db,
455                                                          input => $i,                                                          input => $i,
456                                                          key => $k,                                                          key => $k,
457                                                  );                                                  );
458                                                    $log->debug(sprintf("lookup $db/$i took %.2fs", time() - $t));
459                                          }                                          }
460                                  }                                  }
461                          }                          }
462    
463                          $log->debug("lookup_hash = ", dump( $lookup_hash ));                          $log->debug("lookup_hash = ", sub { dump( $lookup_hash ) });
464                  }                  }
465    
466    
# Line 468  while (my ($database, $db_config) = each Line 468  while (my ($database, $db_config) = each
468    
469                          my $row = $input_db->fetch || next;                          my $row = $input_db->fetch || next;
470    
471                            $total_rows++;
472    
473                          my $mfn = $row->{'000'}->[0];                          my $mfn = $row->{'000'}->[0];
474    
475                          if (! $mfn || $mfn !~ m#^\d+$#) {                          if (! $mfn || $mfn !~ m#^\d+$#) {
# Line 478  while (my ($database, $db_config) = each Line 480  while (my ($database, $db_config) = each
480    
481    
482                          if ($validate) {                          if ($validate) {
483                                  if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {                                  if ( my $errors = $validate->validate_rec( $row, $input_db->dump_ascii ) ) {
484                                          $log->error( "MFN $mfn validation error:\n",                                          $log->error( "MFN $mfn validation error:\n",
485                                                  $validate->report_error( $errors )                                                  $validate->report_error( $errors )
486                                          );                                          );
487                                  }                                  }
488                                    next;   # validation doesn't create any output
489                          }                          }
490    
491                          my $ds = WebPAC::Normalize::data_structure(                          my $ds = WebPAC::Normalize::data_structure(
# Line 501  while (my ($database, $db_config) = each Line 504  while (my ($database, $db_config) = each
504                                  },                                  },
505                          );                          );
506    
507                          $log->debug("ds = ",dump($ds));                          $log->debug("ds = ", sub { dump($ds) }) if ($ds);
508    
509                          $store->save_ds(                          $store->save_ds(
510                                  database => $database,                                  database => $database,
# Line 531  while (my ($database, $db_config) = each Line 534  while (my ($database, $db_config) = each
534    
535                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
536                          }                          }
   
                         $total_rows++;  
537                  }                  }
538    
539                  if ($validate) {                  if ($validate) {

Legend:
Removed from v.736  
changed lines
  Added in v.774

  ViewVC Help
Powered by ViewVC 1.1.26