/[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 511 by dpavlin, Mon May 15 17:49:01 2006 UTC revision 536 by dpavlin, Mon Jun 26 16:39:51 2006 UTC
# Line 11  use WebPAC::Common 0.02; Line 11  use WebPAC::Common 0.02;
11  use WebPAC::Lookup;  use WebPAC::Lookup;
12  use WebPAC::Input 0.03;  use WebPAC::Input 0.03;
13  use WebPAC::Store 0.03;  use WebPAC::Store 0.03;
14  use WebPAC::Normalize::XML;  use WebPAC::Normalize;
 use WebPAC::Normalize::Set;  
15  use WebPAC::Output::TT;  use WebPAC::Output::TT;
16    use WebPAC::Validate;
17  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
18  use Getopt::Long;  use Getopt::Long;
19  use File::Path;  use File::Path;
# Line 53  or C<type> from input Line 53  or C<type> from input
53    
54  path to YAML configuration file  path to YAML configuration file
55    
 =item --force-set  
   
 force conversion C<< normalize->path >> in C<config.yml> from  
 C<.xml> to C<.pl>  
   
56  =item --stats  =item --stats
57    
58  disable indexing and dump statistics about field and subfield  disable indexing and dump statistics about field and subfield
59  usage for each input  usage for each input
60    
61    =item --validate path/to/validation_file
62    
63    turn on extra validation of imput records, see L<WebPAC::Validation>
64    
65  =back  =back
66    
67  =cut  =cut
# Line 74  my $clean = 0; Line 73  my $clean = 0;
73  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
74  my $debug = 0;  my $debug = 0;
75  my $only_filter;  my $only_filter;
 my $force_set = 0;  
76  my $stats = 0;  my $stats = 0;
77    my $validate_path;
78    
79  GetOptions(  GetOptions(
80          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 85  GetOptions( Line 84  GetOptions(
84          "only=s" => \$only_filter,          "only=s" => \$only_filter,
85          "config" => \$config,          "config" => \$config,
86          "debug" => \$debug,          "debug" => \$debug,
         "force-set" => \$force_set,  
87          "stats" => \$stats,          "stats" => \$stats,
88            "validate=s" => \$validate_path,
89  );  );
90    
91  $config = LoadFile($config);  $config = LoadFile($config);
# Line 98  die "no databases in config file!\n" unl Line 97  die "no databases in config file!\n" unl
97  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
98  $log->info( "-" x 79 );  $log->info( "-" x 79 );
99    
100    my $validate;
101    $validate = new WebPAC::Validate(
102            path => $validate_path,
103    ) if ($validate_path);
104    
105  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
106  if ($stats) {  if ($stats) {
107          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
# Line 109  if ($stats) { Line 113  if ($stats) {
113  my $total_rows = 0;  my $total_rows = 0;
114  my $start_t = time();  my $start_t = time();
115    
116    my @links;
117    my $indexer;
118    
119  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
120    
121          my ($only_database,$only_input) = split(m#/#, $only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
122          next if ($only_database && $database !~ m/$only_database/i);          next if ($only_database && $database !~ m/$only_database/i);
123    
         my $indexer;  
   
124          if ($use_indexer) {          if ($use_indexer) {
125                  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");
126                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
# Line 182  while (my ($database, $db_config) = each Line 187  while (my ($database, $db_config) = each
187    
188          foreach my $input (@inputs) {          foreach my $input (@inputs) {
189    
190                  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));
191    
192                  my $type = lc($input->{type});                  my $type = lc($input->{type});
193    
# Line 190  while (my ($database, $db_config) = each Line 195  while (my ($database, $db_config) = each
195    
196                  my $lookup = new WebPAC::Lookup(                  my $lookup = new WebPAC::Lookup(
197                          lookup_file => $input->{lookup},                          lookup_file => $input->{lookup},
198                  );                  ) if ($input->{lookup});
199    
200                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
201    
202                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module lookup '$input->{lookup}'");                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",
203                            $input->{lookup} ? "lookup '$input->{lookup}'" : ""
204                    );
205    
206                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
207                          module => $input_module,                          module => $input_module,
# Line 210  while (my ($database, $db_config) = each Line 217  while (my ($database, $db_config) = each
217                  my $maxmfn = $input_db->open(                  my $maxmfn = $input_db->open(
218                          path => $input->{path},                          path => $input->{path},
219                          code_page => $input->{encoding},        # database encoding                          code_page => $input->{encoding},        # database encoding
220                  );                          %{ $input },
   
                 my $n = new WebPAC::Normalize::XML(  
                 #       filter => { 'foo' => sub { shift } },  
                         db => $db,  
                         lookup_regex => $lookup->regex,  
                         lookup => $lookup,  
                         prefix => $input->{name},  
221                  );                  );
222    
223                  my $rules;                  my $rules;
224                  my $normalize_path = $input->{normalize}->{path};                  my $normalize_path = $input->{normalize}->{path};
225    
226                  if ($force_set) {                  $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i );
                         my $new_norm_path = $normalize_path;  
                         $new_norm_path =~ s/\.xml$/.pl/;  
                         if (-e $new_norm_path) {  
                                 $log->debug("--force-set replaced $normalize_path with $new_norm_path");  
                                 $normalize_path = $new_norm_path;  
                         } else {  
                                 $log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path");  
                         }  
                 }  
227    
228                  if ($normalize_path =~ m/\.xml$/i) {                  my $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";
                         $n->open(  
                                 tag => $input->{normalize}->{tag},  
                                 xml_file => $normalize_path,  
                         );  
                 } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {  
                         $n->open_yaml(  
                                 path => $normalize_path,  
                                 tag => $input->{normalize}->{tag},  
                         );  
                 } elsif ($normalize_path =~ m/\.(?:pl)$/i) {  
                         $n = undef;  
                         $log->info("using WebPAC::Normalize::Set to process $normalize_path");  
                         $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";  
                 }  
229    
230                  foreach my $pos ( 0 ... $input_db->size ) {                  foreach my $pos ( 0 ... $input_db->size ) {
231    
# Line 262  while (my ($database, $db_config) = each Line 239  while (my ($database, $db_config) = each
239                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
240                          }                          }
241    
242                                    
243                          my $ds;                          if ($validate) {
244                          if ($n) {                                  my @errors = $validate->validate_errors( $row );
245                                  $ds = $n->data_structure($row);                                  $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
                         } else {  
                                 $ds = WebPAC::Normalize::Set::data_structure(  
                                         row => $row,  
                                         rules => $rules,  
                                         lookup => $lookup->lookup_hash,  
                                 );  
   
                                 $db->save_ds(  
                                         id => $mfn,  
                                         ds => $ds,  
                                         prefix => $input->{name},  
                                 ) if ($ds && !$stats);  
246                          }                          }
247    
248                                    
249                            my $ds = WebPAC::Normalize::data_structure(
250                                    row => $row,
251                                    rules => $rules,
252                                    lookup => $lookup ? $lookup->lookup_hash : undef,
253                            );
254    
255                            $db->save_ds(
256                                    id => $mfn,
257                                    ds => $ds,
258                                    prefix => $input->{name},
259                            ) if ($ds && !$stats);
260    
261                          $indexer->add(                          $indexer->add(
262                                  id => $input->{name} . "/" . $mfn,                                  id => $input->{name} . "/" . $mfn,
263                                  ds => $ds,                                  ds => $ds,
# Line 308  while (my ($database, $db_config) = each Line 286  while (my ($database, $db_config) = each
286          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY') {
287                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
288                          if ($use_indexer eq 'hyperestraier') {                          if ($use_indexer eq 'hyperestraier') {
289                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");
290                                  $indexer->add_link(                                  push @links, {
291                                          from => $database,                                          from => $database,
292                                          to => $link->{to},                                          to => $link->{to},
293                                          credit => $link->{credit},                                          credit => $link->{credit},
294                                  );                                  };
295                          } else {                          } else {
296                                  $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}]");
297                          }                          }
# Line 322  while (my ($database, $db_config) = each Line 300  while (my ($database, $db_config) = each
300    
301  }  }
302    
303    foreach my $link (@links) {
304            $log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]");
305            $indexer->add_link( %{ $link } );
306    }

Legend:
Removed from v.511  
changed lines
  Added in v.536

  ViewVC Help
Powered by ViewVC 1.1.26