/[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 833 by dpavlin, Wed May 23 20:04:13 2007 UTC revision 1043 by dpavlin, Mon Nov 12 12:35:32 2007 UTC
# Line 9  use lib './lib'; Line 9  use lib './lib';
9  use WebPAC::Common 0.02;  use WebPAC::Common 0.02;
10  use WebPAC::Parser 0.08;  use WebPAC::Parser 0.08;
11  use WebPAC::Input 0.16;  use WebPAC::Input 0.16;
12  use WebPAC::Store 0.14;  use WebPAC::Store 0.15;
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.11;  use WebPAC::Validate 0.11;
# Line 68  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    
71    You can use special variables C<$database> and $C<$input> in this parametar
72    like C<--validate 'conf/validate/$database-$input'> to construct filename
73    
74    =item --validate-delimiters path/to/validate_delimiters_file
75    
76    this option is used with C<--validate> to turn on extra validation of
77    delimiters. If file is non existant, it will be created on first run.
78    
79  =item --marc-generate  =item --marc-generate
80    
81  Generate MARC file. This will automatically be on if file contains C<marc*> directives.  Generate MARC file. This will automatically be on if file contains C<marc*> directives.
# Line 108  my $debug = 0; Line 116  my $debug = 0;
116  my $only_filter;  my $only_filter;
117  my $stats = 0;  my $stats = 0;
118  my $validate_path;  my $validate_path;
119    my $validate_delimiters_path;
120  my $marc_generate = 1;  my $marc_generate = 1;
121  my $marc_lint = 1;  my $marc_lint = 1;
122  my $marc_dump = 0;  my $marc_dump = 0;
# Line 124  GetOptions( Line 133  GetOptions(
133          "clean" => \$clean,          "clean" => \$clean,
134          "one=s" => \$only_filter,          "one=s" => \$only_filter,
135          "only=s" => \$only_filter,          "only=s" => \$only_filter,
136          "config" => \$config_path,          "config=s" => \$config_path,
137          "debug+" => \$debug,          "debug+" => \$debug,
138          "stats" => \$stats,          "stats" => \$stats,
139          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
140            "validate-delimiters=s" => \$validate_delimiters_path,
141          "marc-generate!" => \$marc_generate,          "marc-generate!" => \$marc_generate,
142          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
143          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
# Line 137  GetOptions( Line 147  GetOptions(
147          "help" => \$help,          "help" => \$help,
148  );  );
149    
150    $marc_generate = 0 if ( $validate_delimiters_path );
151    
152  pod2usage(-verbose => 2) if ($help);  pod2usage(-verbose => 2) if ($help);
153    
154  my $config = new WebPAC::Config( path => $config_path );  my $config = new WebPAC::Config( path => $config_path );
155    
156    WebPAC::Normalize::_debug( $debug - 1 ) if $debug > 1;
157    
158  #print "config = ",dump($config) if ($debug);  #print "config = ",dump($config) if ($debug);
159    
160  die "no databases in config file!\n" unless ($config->databases);  die "no databases in config file!\n" unless ($config->databases);
# Line 163  if ($merge) { Line 177  if ($merge) {
177          $log->info("created merge batch file $estcmd_path");          $log->info("created merge batch file $estcmd_path");
178  }  }
179    
   
180  my $validate;  my $validate;
181  $validate = new WebPAC::Validate(  $validate = new WebPAC::Validate(
         path => $validate_path,  
182          delimiters => $config->webpac('delimiters'),          delimiters => $config->webpac('delimiters'),
183  ) if ($validate_path);  ) if ($validate_path || $validate_delimiters_path);
   
184    
185  my $use_indexer = $config->use_indexer;  my $use_indexer = $config->use_indexer;
186  $stats ||= $validate;  $stats ||= $validate;
187  if ($stats) {  if ($stats) {
188          $log->debug("disabled indexing for stats collection");          $log->debug("disabled indexing for stats collection");
189          $use_indexer = undef;          $use_indexer = undef;
190  } else {  } elsif ( $use_indexer ) {
191          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
192  }  }
193    
194  # parse normalize files and create source files for lookup and normalization  # parse normalize files and create source files for lookup and normalization
195    
196  my $parser = new WebPAC::Parser( config => $config );  my ($only_database,$only_input) = split(m#/#, $only_filter) if $only_filter;
197    
198    my $parser = new WebPAC::Parser(
199            config => $config,
200            only_database => $only_database,
201            only_input => $only_input,
202    );
203    
204  my $total_rows = 0;  my $total_rows = 0;
205  my $start_t = time();  my $start_t = time();
# Line 203  sub create_ds_config { Line 220  sub create_ds_config {
220          return $c;          return $c;
221  }  }
222    
223  while (my ($database, $db_config) = each %{ $config->databases }) {  foreach my $database ( sort keys %{ $config->databases } ) {
224            my $db_config = $config->databases->{$database};
225    
         my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);  
226          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
227    
228          if ($parallel) {          if ($parallel) {
# Line 234  while (my ($database, $db_config) = each Line 251  while (my ($database, $db_config) = each
251                  if ($use_indexer eq 'hyperestraier') {                  if ($use_indexer eq 'hyperestraier') {
252    
253                          # open Hyper Estraier database                          # open Hyper Estraier database
254                          use WebPAC::Output::Estraier '0.10';                          require WebPAC::Output::Estraier;
255                          $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );                          $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );
256                                    
257                  } elsif ($use_indexer eq 'hyperestraier-native') {                  } elsif ($use_indexer eq 'hyperestraier-native') {
258    
259                          # open Hyper Estraier database                          # open Hyper Estraier database
260                          use WebPAC::Output::EstraierNative;                          require WebPAC::Output::EstraierNative;
261                          $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } );                          $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } );
262    
263                  } elsif ($use_indexer eq 'kinosearch') {                  } elsif ($use_indexer eq 'kinosearch') {
264    
265                          # open KinoSearch                          die "no longer supported";
                         use WebPAC::Output::KinoSearch;  
                         $indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path});  
                         $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } );  
266    
267                  } else {                  } else {
268                          $log->logdie("unknown use_indexer: $use_indexer");                          $log->logdie("unknown use_indexer: $use_indexer");
269                  }                  }
270    
271                  $log->logide("can't continue without valid indexer") unless ($indexer);                  $log->logdie("can't continue without valid indexer") unless ($indexer);
272          }          }
273    
274    
# Line 288  while (my ($database, $db_config) = each Line 302  while (my ($database, $db_config) = each
302          #          #
303          # now WebPAC::Store          # now WebPAC::Store
304          #          #
305          my $abs_path = abs_path($0);          my $store = new WebPAC::Store({
306          $abs_path =~ s#/[^/]*$#/#;                  debug => $debug,
307            });
308    
         my $db_path = $config->webpac('db_path');  
309    
310          if ($clean) {          #
311                  $log->info("creating new database '$database' in $db_path");          # prepare output
312                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");          #
313          } else {          my @outputs = force_array( $db_config->{output}, sub {
314                  $log->info("working on database '$database' in $db_path");                  $log->error("Database $database doesn't have any outputs defined. Do you want to remove it from configuration?" );
315          }          } );
316    
317          my $store = new WebPAC::Store(          my @output_modules;
318                  path => $db_path,  
319                  debug => $debug,          foreach my $output ( @outputs ) {
320          );  
321    #warn '## output = ',dump( $output );
322    
323                    my $module = $output->{module} || $log->logdie("need module in output section of $database");
324                    $module = 'WebPAC::Output::' . $module unless $module =~ m/::/;
325            
326                    $log->debug("loading output module $module");
327                    eval "require $module";
328    
329                    # add database to arugemnts for output filter
330                    $output->{database} = $database;
331    
332                    $log->debug("calling $module->new(",dump( $output ),")");
333                    my $out = new $module->new( $output );
334                    $out->init;
335    
336                    push @output_modules, $out;
337            }
338    
339    
340          #          #
341          # now, iterate through input formats          # now, iterate through input formats
342          #          #
343    
344          my @inputs;  
345          if (ref($db_config->{input}) eq 'ARRAY') {          my @inputs = force_array( $db_config->{input}, sub {
                 @inputs = @{ $db_config->{input} };  
         } elsif ($db_config->{input}) {  
                 push @inputs, $db_config->{input};  
         } else {  
346                  $log->info("database $database doesn't have inputs defined");                  $log->info("database $database doesn't have inputs defined");
347          }          } );
348    
349          foreach my $input (@inputs) {          foreach my $input (@inputs) {
350    
# Line 327  while (my ($database, $db_config) = each Line 354  while (my ($database, $db_config) = each
354    
355                  my $type = lc($input->{type});                  my $type = lc($input->{type});
356    
357                  die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs')));                  # FIXME check if input module exists
358                    my $input_module = $input->{module};
359    
360                  my $input_module = $config->webpac('inputs')->{$type};                  if ( ! $input_module ) {
361                            if ( grep(/$type/, $config->webpac('inputs')) ) {
362                                    $input_module = $config->webpac('inputs')->{$type};
363                            } else {
364                                    $log->logdie("I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!" );
365                            }
366                    }
367    
368                  my @lookups = $parser->have_lookup_create($database, $input);                  my @lookups = $parser->have_lookup_create($database, $input);
369    
# Line 352  while (my ($database, $db_config) = each Line 386  while (my ($database, $db_config) = each
386                          stats => $stats,                          stats => $stats,
387                          modify_records => $input->{modify_records},                          modify_records => $input->{modify_records},
388                          modify_file => $input->{modify_file},                          modify_file => $input->{modify_file},
389                            input_config => $input,
390                  );                  );
391                  $log->logdie("can't create input using $input_module") unless ($input);                  $log->logdie("can't create input using $input_module") unless ($input);
392    
# Line 436  while (my ($database, $db_config) = each Line 471  while (my ($database, $db_config) = each
471                          print $report_fh "Report for database '$database' input '$input_name' records ",                          print $report_fh "Report for database '$database' input '$input_name' records ",
472                                  $offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n";                                  $offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n";
473                          $log->info("Generating report file $path");                          $log->info("Generating report file $path");
474    
475                            if ( $validate ) {
476                                    $validate->read_validate_file( $validate->fill_in( $validate_path, database => $database, input => $input_name ) ) if ( $validate_path );
477                                    $validate->read_validate_delimiters_file( $validate->fill_in( $validate_delimiters_path, database => $database, input => $input_name ) ) if ( $validate_delimiters_path );
478                            }
479                  }                  }
480    
481                  my $marc;                  my $marc;
# Line 483  while (my ($database, $db_config) = each Line 523  while (my ($database, $db_config) = each
523                  }                  }
524    
525    
526                    # setup input name for all output filters
527                    foreach my $out ( @output_modules ) {
528                            if ( $out->can('input') ) {
529                                    $out->input( $input_name );
530                            } else {
531                                    $log->warn("output filter ",ref($out)," doesn't support input name");
532                            }
533                    }
534    
535    
536                  foreach my $pos ( 0 ... $input_db->size ) {                  foreach my $pos ( 0 ... $input_db->size ) {
537    
538                          my $row = $input_db->fetch || next;                          my $row = $input_db->fetch || next;
# Line 491  while (my ($database, $db_config) = each Line 541  while (my ($database, $db_config) = each
541    
542                          my $mfn = $row->{'000'}->[0];                          my $mfn = $row->{'000'}->[0];
543    
544                          if (! $mfn || $mfn !~ m#^\d+$#) {                          if (! $mfn || $mfn !~ m{^\d+$}) {
545                                  $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");                                  $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");
546                                  $mfn = $pos;                                  $mfn = $pos;
547                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
# Line 515  while (my ($database, $db_config) = each Line 565  while (my ($database, $db_config) = each
565                                  marc_encoding => 'utf-8',                                  marc_encoding => 'utf-8',
566                                  load_row_coderef => sub {                                  load_row_coderef => sub {
567                                          my ($database,$input,$mfn) = @_;                                          my ($database,$input,$mfn) = @_;
568    #warn "### load_row($database,$input,$mfn) from data_structure\n";
569                                          return $store->load_row(                                          return $store->load_row(
570                                                  database => $database,                                                  database => $database,
571                                                  input => $input,                                                  input => $input,
# Line 523  while (my ($database, $db_config) = each Line 574  while (my ($database, $db_config) = each
574                                  },                                  },
575                          );                          );
576    
577                          $log->debug("ds = ", sub { dump($ds) }) if ($ds);                          $log->debug("ds = ", sub { dump($ds) });
578    
579                            if ( $ds ) {
580    
581                                    $store->save_ds(
582                                            database => $database,
583                                            input => $input_name,
584                                            id => $mfn,
585                                            ds => $ds,
586                                    ) if !$stats;
587    
588                                    $indexer->add(
589                                            id => "${input_name}/${mfn}",
590                                            ds => $ds,
591                                            type => $config->get($indexer_config)->{type},
592                                    ) if $indexer;
593    
594                                    foreach my $out ( @output_modules ) {
595                                            $out->add( $mfn, $ds ) if $out->can('add');
596                                    }
597    
598                          $store->save_ds(                          } else {
599                                  database => $database,                                  $log->warn("record $pos didn't produce any output after normalization rules!") unless $marc;
600                                  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);  
601    
602                          if ($marc) {                          if ($marc) {
603                                  my $i = 0;                                  my $i = 0;
604    
605                                  while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {                                  while (my $fields = WebPAC::Normalize::MARC::_get_marc_fields( fetch_next => 1 ) ) {
606                                          $marc->add(                                          $marc->add(
607                                                  id => $mfn . ( $i ? "/$i" : '' ),                                                  id => $mfn . ( $i ? "/$i" : '' ),
608                                                  fields => $fields,                                                  fields => $fields,
609                                                  leader => WebPAC::Normalize::_get_marc_leader(),                                                  leader => WebPAC::Normalize::MARC::_get_marc_leader(),
610                                                  row => $row,                                                  row => $row,
611                                          );                                          );
612                                          $i++;                                          $i++;
# Line 553  while (my ($database, $db_config) = each Line 614  while (my ($database, $db_config) = each
614    
615                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);                                  $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
616                          }                          }
617    
618                  }                  }
619    
620                  if ($validate) {                  if ($validate) {
# Line 562  while (my ($database, $db_config) = each Line 624  while (my ($database, $db_config) = each
624                                  print $report_fh "$errors\n" if ($report_fh);                                  print $report_fh "$errors\n" if ($report_fh);
625                          }                          }
626    
627                          print $report_fh "\nAll possible subfields/delimiter templates:\n", $validate->delimiters_templates, "\n\n";                          print $report_fh "\nAll possible subfields/delimiter templates:\n", $validate->delimiters_templates( report => 1, current_input => 1 ), "\n\n";
628    
629                            # must be last thing that touches $validate for this input
630                            $validate->reset;
631                  }                  }
632    
633                  if ($stats) {                  if ($stats) {
# Line 575  while (my ($database, $db_config) = each Line 640  while (my ($database, $db_config) = each
640                  $marc->finish if ($marc);                  $marc->finish if ($marc);
641    
642                  # close report                  # close report
643                  close($report_fh) if ($report_fh)                  close($report_fh) if ($report_fh);
   
644          }          }
645    
646          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));
647    
648            foreach my $out ( @output_modules ) {
649                    $out->finish if $out->can('finish');
650            }
651    
652          my $dt = time() - $start_t;          my $dt = time() - $start_t;
653          $log->info("$total_rows records ", $indexer ? "indexed " : "",          $log->info("$total_rows records ", $indexer ? "indexed " : "",
654                  sprintf("in %.2f sec [%.2f rec/sec]",                  sprintf("in %.2f sec [%.2f rec/sec]",
# Line 603  if ($parallel) { Line 671  if ($parallel) {
671          $log->info("all parallel processes finished");          $log->info("all parallel processes finished");
672  }  }
673    
674    # save new delimiters if needed
675    $validate->save_delimiters_templates if ( $validate_delimiters_path );
676    
677  #  #
678  # handle links or merge after indexing  # handle links or merge after indexing
679  #  #

Legend:
Removed from v.833  
changed lines
  Added in v.1043

  ViewVC Help
Powered by ViewVC 1.1.26