/[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 732 by dpavlin, Fri Sep 29 20:25:34 2006 UTC revision 775 by dpavlin, Sun Nov 5 12:28:37 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.21;  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;
16  use WebPAC::Output::MARC;  use WebPAC::Output::MARC;
# 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 146  die "no databases in config file!\n" unl Line 135  die "no databases in config file!\n" unl
135    
136  $log->info( "-" x 79 );  $log->info( "-" x 79 );
137    
138    my $log_file = 'log';
139    
140    if (-e $log_file ) {    # && -s $log_file > 5 * 1024 * 1024) {
141            $log->info("moved old log with ", -s $log_file, " bytes to '${log_file}.old'");
142            rename $log_file, "${log_file}.old" || $log->logwarn("can't rename $log_file to ${log_file}.old: $!");
143    }
144    
145  my $estcmd_fh;  my $estcmd_fh;
146  my $estcmd_path = './estcmd-merge.sh';  my $estcmd_path = './estcmd-merge.sh';
# Line 164  $validate = new WebPAC::Validate( Line 159  $validate = new WebPAC::Validate(
159    
160    
161  my $use_indexer = $config->use_indexer;  my $use_indexer = $config->use_indexer;
162    $stats ||= $validate;
163  if ($stats) {  if ($stats) {
164          $log->debug("option --stats disables update of indexing engine...");          $log->debug("disabled indexing for stats collection");
165          $use_indexer = undef;          $use_indexer = undef;
166  } else {  } else {
167          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
168  }  }
169    
 # disable indexing when creating marc  
 $use_indexer = undef if ($marc_normalize);  
   
170  # parse normalize files and create source files for lookup and normalization  # parse normalize files and create source files for lookup and normalization
171    
172  my $parser = new WebPAC::Parser( config => $config );  my $parser = new WebPAC::Parser( config => $config );
# Line 212  while (my ($database, $db_config) = each Line 205  while (my ($database, $db_config) = each
205          }          }
206    
207          my $indexer;          my $indexer;
208          if ($use_indexer) {          if ($use_indexer && $parser->have_rules( 'search', $database )) {
209    
210                  my $cfg_name = $use_indexer;                  my $cfg_name = $use_indexer;
211                  $cfg_name =~ s/\-.*$//;                  $cfg_name =~ s/\-.*$//;
# Line 387  while (my ($database, $db_config) = each Line 380  while (my ($database, $db_config) = each
380                          lookup_coderef => $lookup_coderef,                          lookup_coderef => $lookup_coderef,
381                          lookup => $lookup_jar,                          lookup => $lookup_jar,
382                          %{ $input },                          %{ $input },
383                            load_row => sub {
384                                    my $a = shift;
385                                    return $store->load_row(
386                                            database => $database,
387                                            input => $input_name,
388                                            id => $a->{id},
389                                    );
390                            },
391                            save_row => sub {
392                                    my $a = shift;
393                                    return $store->save_row(
394                                            database => $database,
395                                            input => $input_name,
396                                            id => $a->{id},
397                                            row => $a->{row},
398                                    );
399                            },
400    
401                  );                  );
402    
403                  my $lookup_data = WebPAC::Normalize::_get_lookup();                  my $lookup_data = WebPAC::Normalize::_get_lookup();
404    
405                  if (defined( $lookup_data->{$database}->{$input_name} )) {                  if (defined( $lookup_data->{$database}->{$input_name} )) {
406                          $log->debug("created following lookups: ", dump( $lookup_data ));                          $log->debug("created following lookups: ", sub { dump( $lookup_data ) } );
407    
408                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {
409                                  $store->save_lookup(                                  $store->save_lookup(
# Line 415  while (my ($database, $db_config) = each Line 426  while (my ($database, $db_config) = each
426                  }                  }
427    
428                  my $marc;                  my $marc;
429                  if ($marc_normalize) {                  if ($parser->have_rules( 'marc', $database, $input_name )) {
430                          $marc = new WebPAC::Output::MARC(                          $marc = new WebPAC::Output::MARC(
431                                  path => $marc_output || "out/marc/${database}-${input_name}.marc",                                  path => "out/marc/${database}-${input_name}.marc",
432                                  lint => $marc_lint,                                  lint => $marc_lint,
433                                  dump => $marc_dump,                                  dump => $marc_dump,
434                          );                          );
# Line 443  while (my ($database, $db_config) = each Line 454  while (my ($database, $db_config) = each
454                          foreach my $db (keys %$depends) {                          foreach my $db (keys %$depends) {
455                                  foreach my $i (keys %{$depends->{$db}}) {                                  foreach my $i (keys %{$depends->{$db}}) {
456                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {
457                                                    my $t = time();
458                                                  $log->debug("loading lookup $db/$i");                                                  $log->debug("loading lookup $db/$i");
459                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(
460                                                          database => $db,                                                          database => $db,
461                                                          input => $i,                                                          input => $i,
462                                                          key => $k,                                                          key => $k,
463                                                  );                                                  );
464                                                    $log->debug(sprintf("lookup $db/$i took %.2fs", time() - $t));
465                                          }                                          }
466                                  }                                  }
467                          }                          }
468    
469                          $log->debug("lookup_hash = ", dump( $lookup_hash ));                          $log->debug("lookup_hash = ", sub { dump( $lookup_hash ) });
470                  }                  }
471    
472    
# Line 461  while (my ($database, $db_config) = each Line 474  while (my ($database, $db_config) = each
474    
475                          my $row = $input_db->fetch || next;                          my $row = $input_db->fetch || next;
476    
477                            $total_rows++;
478    
479                          my $mfn = $row->{'000'}->[0];                          my $mfn = $row->{'000'}->[0];
480    
481                          if (! $mfn || $mfn !~ m#^\d+$#) {                          if (! $mfn || $mfn !~ m#^\d+$#) {
# Line 471  while (my ($database, $db_config) = each Line 486  while (my ($database, $db_config) = each
486    
487    
488                          if ($validate) {                          if ($validate) {
489                                  if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {                                  if ( my $errors = $validate->validate_rec( $row, $input_db->dump_ascii ) ) {
490                                          $log->error( "MFN $mfn validation error:\n",                                          $log->error( "MFN $mfn validation error:\n",
491                                                  $validate->report_error( $errors )                                                  $validate->report_error( $errors )
492                                          );                                          );
493                                  }                                  }
494                                    next;   # validation doesn't create any output
495                          }                          }
496    
497                          my $ds = WebPAC::Normalize::data_structure(                          my $ds = WebPAC::Normalize::data_structure(
# Line 484  while (my ($database, $db_config) = each Line 500  while (my ($database, $db_config) = each
500                                  lookup => $lookup_hash,                                  lookup => $lookup_hash,
501                                  config => create_ds_config( $db_config, $database, $input, $mfn ),                                  config => create_ds_config( $db_config, $database, $input, $mfn ),
502                                  marc_encoding => 'utf-8',                                  marc_encoding => 'utf-8',
503                                  load_ds_coderef => sub {                                  load_row_coderef => sub {
504                                          my ($database,$input,$mfn) = @_;                                          my ($database,$input,$mfn) = @_;
505                                          return $store->load_ds(                                          return $store->load_row(
506                                                  database => $database,                                                  database => $database,
507                                                  input => $input,                                                  input => $input,
508                                                  id => $mfn,                                                  id => $mfn,
# Line 494  while (my ($database, $db_config) = each Line 510  while (my ($database, $db_config) = each
510                                  },                                  },
511                          );                          );
512    
513                            $log->debug("ds = ", sub { dump($ds) }) if ($ds);
514    
515                          $store->save_ds(                          $store->save_ds(
516                                  database => $database,                                  database => $database,
517                                  input => $input_name,                                  input => $input_name,
# Line 522  while (my ($database, $db_config) = each Line 540  while (my ($database, $db_config) = each
540    
541                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
542                          }                          }
   
                         $total_rows++;  
543                  }                  }
544    
545                  if ($validate) {                  if ($validate) {

Legend:
Removed from v.732  
changed lines
  Added in v.775

  ViewVC Help
Powered by ViewVC 1.1.26