/[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 510 by dpavlin, Mon May 15 17:38:22 2006 UTC revision 529 by dpavlin, Mon May 22 19:34:45 2006 UTC
# Line 14  use WebPAC::Store 0.03; Line 14  use WebPAC::Store 0.03;
14  use WebPAC::Normalize::XML;  use WebPAC::Normalize::XML;
15  use WebPAC::Normalize::Set;  use WebPAC::Normalize::Set;
16  use WebPAC::Output::TT;  use WebPAC::Output::TT;
17    use WebPAC::Validate;
18  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
19  use Getopt::Long;  use Getopt::Long;
20  use File::Path;  use File::Path;
# Line 63  C<.xml> to C<.pl> Line 64  C<.xml> to C<.pl>
64  disable indexing and dump statistics about field and subfield  disable indexing and dump statistics about field and subfield
65  usage for each input  usage for each input
66    
67    =item --validate path/to/validation_file
68    
69    turn on extra validation of imput records, see L<WebPAC::Validation>
70    
71  =back  =back
72    
73  =cut  =cut
# Line 76  my $debug = 0; Line 81  my $debug = 0;
81  my $only_filter;  my $only_filter;
82  my $force_set = 0;  my $force_set = 0;
83  my $stats = 0;  my $stats = 0;
84    my $validate_path;
85    
86  GetOptions(  GetOptions(
87          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 87  GetOptions( Line 93  GetOptions(
93          "debug" => \$debug,          "debug" => \$debug,
94          "force-set" => \$force_set,          "force-set" => \$force_set,
95          "stats" => \$stats,          "stats" => \$stats,
96            "validate=s" => \$validate_path,
97  );  );
98    
99  $config = LoadFile($config);  $config = LoadFile($config);
# Line 98  die "no databases in config file!\n" unl Line 105  die "no databases in config file!\n" unl
105  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
106  $log->info( "-" x 79 );  $log->info( "-" x 79 );
107    
108    my $validate;
109    $validate = new WebPAC::Validate(
110            path => $validate_path,
111    ) if ($validate_path);
112    
113  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
114  if ($stats) {  if ($stats) {
115          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
# Line 109  if ($stats) { Line 121  if ($stats) {
121  my $total_rows = 0;  my $total_rows = 0;
122  my $start_t = time();  my $start_t = time();
123    
124    my @links;
125    my $indexer;
126    
127  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
128    
129          my ($only_database,$only_input) = split(m#/#, $only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
130          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
131    
         my $indexer;  
   
132          if ($use_indexer) {          if ($use_indexer) {
133                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
134                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
# Line 152  while (my ($database, $db_config) = each Line 165  while (my ($database, $db_config) = each
165          my $db_path = $config->{webpac}->{db_path} . '/' . $database;          my $db_path = $config->{webpac}->{db_path} . '/' . $database;
166    
167          if ($clean) {          if ($clean) {
168                  $log->info("creating new database $database in $db_path");                  $log->info("creating new database '$database' in $db_path");
169                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");
170          } else {          } else {
171                  $log->debug("working on $database in $db_path");                  $log->info("working on database '$database' in $db_path");
172          }          }
173    
174          my $db = new WebPAC::Store(          my $db = new WebPAC::Store(
# Line 182  while (my ($database, $db_config) = each Line 195  while (my ($database, $db_config) = each
195    
196          foreach my $input (@inputs) {          foreach my $input (@inputs) {
197    
198                  next if ($only_input && $input->{name} =~ m#$only_input#i || $input->{type} =~ m#$only_input#i);                  next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
199    
200                  my $type = lc($input->{type});                  my $type = lc($input->{type});
201    
# Line 190  while (my ($database, $db_config) = each Line 203  while (my ($database, $db_config) = each
203    
204                  my $lookup = new WebPAC::Lookup(                  my $lookup = new WebPAC::Lookup(
205                          lookup_file => $input->{lookup},                          lookup_file => $input->{lookup},
206                  );                  ) if ($input->{lookup});
207    
208                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
209    
210                  $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'");                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",
211                            $input->{lookup} ? "lookup '$input->{lookup}'" : ""
212                    );
213    
214                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
215                          module => $input_module,                          module => $input_module,
# Line 210  while (my ($database, $db_config) = each Line 225  while (my ($database, $db_config) = each
225                  my $maxmfn = $input_db->open(                  my $maxmfn = $input_db->open(
226                          path => $input->{path},                          path => $input->{path},
227                          code_page => $input->{encoding},        # database encoding                          code_page => $input->{encoding},        # database encoding
228                            %{ $input },
229                  );                  );
230    
231                  my $n = new WebPAC::Normalize::XML(                  my $n = new WebPAC::Normalize::XML(
232                  #       filter => { 'foo' => sub { shift } },                  #       filter => { 'foo' => sub { shift } },
233                          db => $db,                          db => $db,
234                          lookup_regex => $lookup->regex,                          lookup_regex => $lookup ? $lookup->regex : undef,
235                          lookup => $lookup,                          lookup => $lookup,
236                          prefix => $input->{name},                          prefix => $input->{name},
237                  );                  );
# Line 262  while (my ($database, $db_config) = each Line 278  while (my ($database, $db_config) = each
278                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
279                          }                          }
280    
281    
282                            if ($validate) {
283                                    my @errors = $validate->validate_errors( $row );
284                                    $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
285                            }
286    
287                                                                    
288                          my $ds;                          my $ds;
289                          if ($n) {                          if ($n) {
# Line 270  while (my ($database, $db_config) = each Line 292  while (my ($database, $db_config) = each
292                                  $ds = WebPAC::Normalize::Set::data_structure(                                  $ds = WebPAC::Normalize::Set::data_structure(
293                                          row => $row,                                          row => $row,
294                                          rules => $rules,                                          rules => $rules,
295                                          lookup => $lookup->lookup_hash,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
296                                  );                                  );
297    
298                                  $db->save_ds(                                  $db->save_ds(
# Line 296  while (my ($database, $db_config) = each Line 318  while (my ($database, $db_config) = each
318          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));
319    
320          my $dt = time() - $start_t;          my $dt = time() - $start_t;
321          $log->info("$total_rows records indexed in " .          $log->info("$total_rows records ", $indexer ? "indexed " : "",
322                  sprintf("%.2f sec [%.2f rec/sec]",                  sprintf("in %.2f sec [%.2f rec/sec]",
323                          $dt, ($total_rows / $dt)                          $dt, ($total_rows / $dt)
324                  )                  )
325          );          );
# Line 308  while (my ($database, $db_config) = each Line 330  while (my ($database, $db_config) = each
330          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY') {
331                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
332                          if ($use_indexer eq 'hyperestraier') {                          if ($use_indexer eq 'hyperestraier') {
333                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");
334                                  $indexer->add_link(                                  push @links, {
335                                          from => $database,                                          from => $database,
336                                          to => $link->{to},                                          to => $link->{to},
337                                          credit => $link->{credit},                                          credit => $link->{credit},
338                                  );                                  };
339                          } else {                          } else {
340                                  $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");                                  $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
341                          }                          }
# Line 322  while (my ($database, $db_config) = each Line 344  while (my ($database, $db_config) = each
344    
345  }  }
346    
347    foreach my $link (@links) {
348            $log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]");
349            $indexer->add_link( %{ $link } );
350    }

Legend:
Removed from v.510  
changed lines
  Added in v.529

  ViewVC Help
Powered by ViewVC 1.1.26