/[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 539 by dpavlin, Thu Jun 29 15:29:32 2006 UTC revision 552 by dpavlin, Fri Jun 30 20:43:18 2006 UTC
# Line 19  use Getopt::Long; Line 19  use Getopt::Long;
19  use File::Path;  use File::Path;
20  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
21  use File::Slurp;  use File::Slurp;
22    use MARC::Record 2.0;   # need 2.0 for utf-8 encoding see marcpm.sf.net
23    
24  =head1 NAME  =head1 NAME
25    
# Line 62  usage for each input Line 63  usage for each input
63    
64  turn on extra validation of imput records, see L<WebPAC::Validation>  turn on extra validation of imput records, see L<WebPAC::Validation>
65    
66    =item --marc-normalize conf/normalize/mapping.pl
67    
68    This option specifies normalisation file for MARC creation
69    
70    =item --marc-output out/marc/test.marc
71    
72    Optional path to output file
73    
74  =back  =back
75    
76  =cut  =cut
# Line 75  my $debug = 0; Line 84  my $debug = 0;
84  my $only_filter;  my $only_filter;
85  my $stats = 0;  my $stats = 0;
86  my $validate_path;  my $validate_path;
87    my ($marc_normalize, $marc_output);
88    
89  GetOptions(  GetOptions(
90          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 86  GetOptions( Line 96  GetOptions(
96          "debug" => \$debug,          "debug" => \$debug,
97          "stats" => \$stats,          "stats" => \$stats,
98          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
99            "marc-normalize=s" => \$marc_normalize,
100            "marc-output=s" => \$marc_output,
101  );  );
102    
103  $config = LoadFile($config);  $config = LoadFile($config);
# Line 110  if ($stats) { Line 122  if ($stats) {
122          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
123  }  }
124    
125    # disable indexing when creating marc
126    $use_indexer = undef if ($marc_normalize);
127    
128  my $total_rows = 0;  my $total_rows = 0;
129  my $start_t = time();  my $start_t = time();
130    
# Line 223  while (my ($database, $db_config) = each Line 238  while (my ($database, $db_config) = each
238                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?
239                          @{ $input->{normalize} } : ( $input->{normalize} );                          @{ $input->{normalize} } : ( $input->{normalize} );
240    
241                    if ($marc_normalize) {
242                            @norm_array = ( {
243                                    path => $marc_normalize,
244                                    output => $marc_output || 'out/marc/' . $database . '-' . $input->{name} . '.marc',
245                            } );
246                    }
247    
248                  foreach my $normalize (@norm_array) {                  foreach my $normalize (@norm_array) {
249    
                         my $rules;  
250                          my $normalize_path = $normalize->{path} || $log->logdie("can't find normalize path in config");                          my $normalize_path = $normalize->{path} || $log->logdie("can't find normalize path in config");
251    
252                          $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i );                          $log->logdie("Found '$normalize_path' as normalization file which isn't supported any more!") unless ( $normalize_path =~ m!\.pl$!i );
# Line 234  while (my ($database, $db_config) = each Line 255  while (my ($database, $db_config) = each
255    
256                          $log->info("Using $normalize_path for normalization...");                          $log->info("Using $normalize_path for normalization...");
257    
258                            my $marc_fh;
259                            if (my $path = $normalize->{output}) {
260                                    open($marc_fh, '>', $path) ||
261                                            $log->logdie("can't open MARC output $path: $!");
262    
263                                    $log->info("Creating MARC export file $path\n");
264                            }
265    
266                          # reset position in database                          # reset position in database
267                          $input_db->seek(1);                          $input_db->seek(1);
268    
# Line 260  while (my ($database, $db_config) = each Line 289  while (my ($database, $db_config) = each
289                                          row => $row,                                          row => $row,
290                                          rules => $rules,                                          rules => $rules,
291                                          lookup => $lookup ? $lookup->lookup_hash : undef,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
292                                            marc_encoding => 'utf-8',
293                                  );                                  );
294    
295                                  $db->save_ds(                                  $db->save_ds(
# Line 272  while (my ($database, $db_config) = each Line 302  while (my ($database, $db_config) = each
302                                          id => $input->{name} . "/" . $mfn,                                          id => $input->{name} . "/" . $mfn,
303                                          ds => $ds,                                          ds => $ds,
304                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
305                                  ) if ($indexer);                                  ) if ($indexer && $ds);
306    
307                                    if ($marc_fh) {
308                                            my $marc = new MARC::Record;
309                                            $marc->encoding( 'utf-8' );
310                                            $marc->add_fields( WebPAC::Normalize::_get_marc_fields() );
311                                            print $marc_fh $marc->as_usmarc;
312                                    }
313    
314                                  $total_rows++;                                  $total_rows++;
315                          }                          }
316    
317                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
318    
319                  };                          # close MARC file
320                            close($marc_fh) if ($marc_fh);
321    
322                    }
323    
324          }          }
325    
# Line 295  while (my ($database, $db_config) = each Line 335  while (my ($database, $db_config) = each
335          #          #
336          # add Hyper Estraier links to other databases          # add Hyper Estraier links to other databases
337          #          #
338          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
339                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
340                          if ($use_indexer eq 'hyperestraier') {                          if ($use_indexer eq 'hyperestraier') {
341                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");

Legend:
Removed from v.539  
changed lines
  Added in v.552

  ViewVC Help
Powered by ViewVC 1.1.26