/[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 731 by dpavlin, Fri Sep 29 20:18:39 2006 UTC revision 790 by dpavlin, Wed Dec 13 10:08:27 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 21  use Time::HiRes qw/time/; Line 21  use Time::HiRes qw/time/;
21  use File::Slurp;  use File::Slurp;
22  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
23  use Storable qw/dclone/;  use Storable qw/dclone/;
24    use Pod::Usage qw/pod2usage/;
25    
26  use Proc::Queue size => 1;  use Proc::Queue size => 1;
27  use POSIX ":sys_wait_h"; # imports WNOHANG  use POSIX ":sys_wait_h"; # imports WNOHANG
# Line 31  run.pl - start WebPAC indexing Line 32  run.pl - start WebPAC indexing
32    
33  B<this command will probably go away. Don't get used to it!>  B<this command will probably go away. Don't get used to it!>
34    
35  Options:  =head1 OPTIONS
36    
37  =over 4  =over 4
38    
# Line 67  and subfield usage for each input Line 68  and subfield usage for each input
68    
69  turn on extra validation of imput records, see L<WebPAC::Validation>  turn on extra validation of imput records, see L<WebPAC::Validation>
70    
 =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  
   
71  =item --marc-lint  =item --marc-lint
72    
73  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
74  messages with C<--no-marc-lint>.  messages with C<--no-marc-lint>.
75    
76  =item --marc-dump  =item --marc-dump
# Line 110  my $debug = 0; Line 103  my $debug = 0;
103  my $only_filter;  my $only_filter;
104  my $stats = 0;  my $stats = 0;
105  my $validate_path;  my $validate_path;
 my ($marc_normalize, $marc_output);  
106  my $marc_lint = 1;  my $marc_lint = 1;
107  my $marc_dump = 0;  my $marc_dump = 0;
108  my $parallel = 0;  my $parallel = 0;
109  my $only_links = 0;  my $only_links = 0;
110  my $merge = 0;  my $merge = 0;
111    my $help;
112    
113  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
114    
# Line 129  GetOptions( Line 122  GetOptions(
122          "debug+" => \$debug,          "debug+" => \$debug,
123          "stats" => \$stats,          "stats" => \$stats,
124          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
         "marc-normalize=s" => \$marc_normalize,  
         "marc-output=s" => \$marc_output,  
125          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
126          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
127          "parallel=i" => \$parallel,          "parallel=i" => \$parallel,
128          "only-links!" => \$only_links,          "only-links!" => \$only_links,
129          "merge" => \$merge,          "merge" => \$merge,
130            "help" => \$help,
131  );  );
132    
133    pod2usage(-verbose => 2) if ($help);
134    
135  my $config = new WebPAC::Config( path => $config_path );  my $config = new WebPAC::Config( path => $config_path );
136    
137  #print "config = ",dump($config) if ($debug);  #print "config = ",dump($config) if ($debug);
# Line 146  die "no databases in config file!\n" unl Line 140  die "no databases in config file!\n" unl
140    
141  $log->info( "-" x 79 );  $log->info( "-" x 79 );
142    
143    my $log_file = 'log';
144    
145    if (-e $log_file ) {    # && -s $log_file > 5 * 1024 * 1024) {
146            $log->info("moved old log with ", -s $log_file, " bytes to '${log_file}.old'");
147            rename $log_file, "${log_file}.old" || $log->logwarn("can't rename $log_file to ${log_file}.old: $!");
148    }
149    
150  my $estcmd_fh;  my $estcmd_fh;
151  my $estcmd_path = './estcmd-merge.sh';  my $estcmd_path = './estcmd-merge.sh';
# Line 164  $validate = new WebPAC::Validate( Line 164  $validate = new WebPAC::Validate(
164    
165    
166  my $use_indexer = $config->use_indexer;  my $use_indexer = $config->use_indexer;
167    $stats ||= $validate;
168  if ($stats) {  if ($stats) {
169          $log->debug("option --stats disables update of indexing engine...");          $log->debug("disabled indexing for stats collection");
170          $use_indexer = undef;          $use_indexer = undef;
171  } else {  } else {
172          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
173  }  }
174    
 # disable indexing when creating marc  
 $use_indexer = undef if ($marc_normalize);  
   
175  # parse normalize files and create source files for lookup and normalization  # parse normalize files and create source files for lookup and normalization
176    
177  my $parser = new WebPAC::Parser( config => $config );  my $parser = new WebPAC::Parser( config => $config );
# Line 212  while (my ($database, $db_config) = each Line 210  while (my ($database, $db_config) = each
210          }          }
211    
212          my $indexer;          my $indexer;
213          if ($use_indexer) {          if ($use_indexer && $parser->have_rules( 'search', $database )) {
214    
215                  my $cfg_name = $use_indexer;                  my $cfg_name = $use_indexer;
216                  $cfg_name =~ s/\-.*$//;                  $cfg_name =~ s/\-.*$//;
# Line 366  while (my ($database, $db_config) = each Line 364  while (my ($database, $db_config) = each
364    
365                                  WebPAC::Normalize::data_structure(                                  WebPAC::Normalize::data_structure(
366                                          row => $rec,                                          row => $rec,
367                                          rules => "_debug(2); $rules _debug(0)",                                          rules => $rules,
368                                          config => create_ds_config( $db_config, $database, $input, $mfn ),                                          config => create_ds_config( $db_config, $database, $input, $mfn ),
369                                  );                                  );
370    
371                                  warn "current lookup: ", dump(WebPAC::Normalize::_get_lookup());                                  #warn "current lookup: ", dump(WebPAC::Normalize::_get_lookup());
372                          };                          };
373    
374                          WebPAC::Normalize::_set_lookup( undef );                          WebPAC::Normalize::_set_lookup( undef );
# Line 387  while (my ($database, $db_config) = each Line 385  while (my ($database, $db_config) = each
385                          lookup_coderef => $lookup_coderef,                          lookup_coderef => $lookup_coderef,
386                          lookup => $lookup_jar,                          lookup => $lookup_jar,
387                          %{ $input },                          %{ $input },
388                            load_row => sub {
389                                    my $a = shift;
390                                    return $store->load_row(
391                                            database => $database,
392                                            input => $input_name,
393                                            id => $a->{id},
394                                    );
395                            },
396                            save_row => sub {
397                                    my $a = shift;
398                                    return $store->save_row(
399                                            database => $database,
400                                            input => $input_name,
401                                            id => $a->{id},
402                                            row => $a->{row},
403                                    );
404                            },
405    
406                  );                  );
407    
408                  my $lookup_data = WebPAC::Normalize::_get_lookup();                  my $lookup_data = WebPAC::Normalize::_get_lookup();
409    
410                  if (defined( $lookup_data->{$database}->{$input_name} )) {                  if (defined( $lookup_data->{$database}->{$input_name} )) {
411                          $log->debug("created following lookups: ", dump( $lookup_data ));                          $log->debug("created following lookups: ", sub { dump( $lookup_data ) } );
412    
413                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {                          foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {
414                                  $store->save_lookup(                                  $store->save_lookup(
# Line 415  while (my ($database, $db_config) = each Line 431  while (my ($database, $db_config) = each
431                  }                  }
432    
433                  my $marc;                  my $marc;
434                  if ($marc_normalize) {                  if ($parser->have_rules( 'marc', $database, $input_name )) {
435                          $marc = new WebPAC::Output::MARC(                          $marc = new WebPAC::Output::MARC(
436                                  path => $marc_output || "out/marc/${database}-${input_name}.marc",                                  path => "out/marc/${database}-${input_name}.marc",
437                                  lint => $marc_lint,                                  lint => $marc_lint,
438                                  dump => $marc_dump,                                  dump => $marc_dump,
439                          );                          );
# Line 443  while (my ($database, $db_config) = each Line 459  while (my ($database, $db_config) = each
459                          foreach my $db (keys %$depends) {                          foreach my $db (keys %$depends) {
460                                  foreach my $i (keys %{$depends->{$db}}) {                                  foreach my $i (keys %{$depends->{$db}}) {
461                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {                                          foreach my $k (keys %{$depends->{$db}->{$i}}) {
462                                                    my $t = time();
463                                                  $log->debug("loading lookup $db/$i");                                                  $log->debug("loading lookup $db/$i");
464                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(                                                  $lookup_hash->{$db}->{$i}->{$k} = $store->load_lookup(
465                                                          database => $db,                                                          database => $db,
466                                                          input => $i,                                                          input => $i,
467                                                          key => $k,                                                          key => $k,
468                                                  );                                                  );
469                                                    $log->debug(sprintf("lookup $db/$i took %.2fs", time() - $t));
470                                          }                                          }
471                                  }                                  }
472                          }                          }
473    
474                          $log->debug("lookup_hash = ", dump( $lookup_hash ));                          $log->debug("lookup_hash = ", sub { dump( $lookup_hash ) });
475                  }                  }
476    
477    
# Line 461  while (my ($database, $db_config) = each Line 479  while (my ($database, $db_config) = each
479    
480                          my $row = $input_db->fetch || next;                          my $row = $input_db->fetch || next;
481    
482                            $total_rows++;
483    
484                          my $mfn = $row->{'000'}->[0];                          my $mfn = $row->{'000'}->[0];
485    
486                          if (! $mfn || $mfn !~ m#^\d+$#) {                          if (! $mfn || $mfn !~ m#^\d+$#) {
# Line 471  while (my ($database, $db_config) = each Line 491  while (my ($database, $db_config) = each
491    
492    
493                          if ($validate) {                          if ($validate) {
494                                  if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {                                  if ( my $errors = $validate->validate_rec( $row, $input_db->dump_ascii ) ) {
495                                          $log->error( "MFN $mfn validation error:\n",                                          $log->error( "MFN $mfn validation error:\n",
496                                                  $validate->report_error( $errors )                                                  $validate->report_error( $errors )
497                                          );                                          );
498                                  }                                  }
499                                    next;   # validation doesn't create any output
500                          }                          }
501    
502                          my $ds = WebPAC::Normalize::data_structure(                          my $ds = WebPAC::Normalize::data_structure(
# Line 484  while (my ($database, $db_config) = each Line 505  while (my ($database, $db_config) = each
505                                  lookup => $lookup_hash,                                  lookup => $lookup_hash,
506                                  config => create_ds_config( $db_config, $database, $input, $mfn ),                                  config => create_ds_config( $db_config, $database, $input, $mfn ),
507                                  marc_encoding => 'utf-8',                                  marc_encoding => 'utf-8',
508                                  load_ds_coderef => sub {                                  load_row_coderef => sub {
509                                          my ($database,$input,$mfn) = @_;                                          my ($database,$input,$mfn) = @_;
510                                          return $store->load_ds(                                          return $store->load_row(
511                                                  database => $database,                                                  database => $database,
512                                                  input => $input,                                                  input => $input,
513                                                  id => $mfn,                                                  id => $mfn,
# Line 494  while (my ($database, $db_config) = each Line 515  while (my ($database, $db_config) = each
515                                  },                                  },
516                          );                          );
517    
518                            $log->debug("ds = ", sub { dump($ds) }) if ($ds);
519    
520                          $store->save_ds(                          $store->save_ds(
521                                  database => $database,                                  database => $database,
522                                  input => $input_name,                                  input => $input_name,
# Line 522  while (my ($database, $db_config) = each Line 545  while (my ($database, $db_config) = each
545    
546                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
547                          }                          }
   
                         $total_rows++;  
548                  }                  }
549    
550                  if ($validate) {                  if ($validate) {

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

  ViewVC Help
Powered by ViewVC 1.1.26