/[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 559 by dpavlin, Sun Jul 2 12:42:02 2006 UTC
# Line 4  use strict; Line 4  use strict;
4    
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
 use Data::Dumper;  
7  use lib './lib';  use lib './lib';
8    
9  use WebPAC::Common 0.02;  use WebPAC::Common 0.02;
# Line 19  use Getopt::Long; Line 18  use Getopt::Long;
18  use File::Path;  use File::Path;
19  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
20  use File::Slurp;  use File::Slurp;
21    use MARC::Record 2.0;   # need 2.0 for utf-8 encoding see marcpm.sf.net
22    use MARC::Lint;
23    use Data::Dump qw/dump/;
24    
25  =head1 NAME  =head1 NAME
26    
# Line 62  usage for each input Line 64  usage for each input
64    
65  turn on extra validation of imput records, see L<WebPAC::Validation>  turn on extra validation of imput records, see L<WebPAC::Validation>
66    
67    =item --marc-normalize conf/normalize/mapping.pl
68    
69    This option specifies normalisation file for MARC creation
70    
71    =item --marc-output out/marc/test.marc
72    
73    Optional path to output file
74    
75    =item --marc-lint
76    
77    By default turned on if C<--marc-normalize> is used. You can disable lint
78    messages with C<--no-marc-lint>.
79    
80    =item --marc-dump
81    
82    Force dump or input and marc record for debugging.
83    
84  =back  =back
85    
86  =cut  =cut
# Line 75  my $debug = 0; Line 94  my $debug = 0;
94  my $only_filter;  my $only_filter;
95  my $stats = 0;  my $stats = 0;
96  my $validate_path;  my $validate_path;
97    my ($marc_normalize, $marc_output);
98    my $marc_lint = 1;
99    my $marc_dump = 0;
100    
101  GetOptions(  GetOptions(
102          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 86  GetOptions( Line 108  GetOptions(
108          "debug" => \$debug,          "debug" => \$debug,
109          "stats" => \$stats,          "stats" => \$stats,
110          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
111            "marc-normalize=s" => \$marc_normalize,
112            "marc-output=s" => \$marc_output,
113            "marc-lint!" => \$marc_lint,
114            "marc-dump!" => \$marc_dump,
115  );  );
116    
117  $config = LoadFile($config);  $config = LoadFile($config);
118    
119  print "config = ",Dumper($config) if ($debug);  print "config = ",dump($config) if ($debug);
120    
121  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
122    
# Line 110  if ($stats) { Line 136  if ($stats) {
136          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
137  }  }
138    
139    # disable indexing when creating marc
140    $use_indexer = undef if ($marc_normalize);
141    
142  my $total_rows = 0;  my $total_rows = 0;
143  my $start_t = time();  my $start_t = time();
144    
145  my @links;  my @links;
146  my $indexer;  my $indexer;
147    
148    my $lint = new MARC::Lint if ($marc_lint);
149    
150  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
151    
152          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
# Line 223  while (my ($database, $db_config) = each Line 254  while (my ($database, $db_config) = each
254                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?                  my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?
255                          @{ $input->{normalize} } : ( $input->{normalize} );                          @{ $input->{normalize} } : ( $input->{normalize} );
256    
257                    if ($marc_normalize) {
258                            @norm_array = ( {
259                                    path => $marc_normalize,
260                                    output => $marc_output || 'out/marc/' . $database . '-' . $input->{name} . '.marc',
261                            } );
262                    }
263    
264                  foreach my $normalize (@norm_array) {                  foreach my $normalize (@norm_array) {
265    
                         my $rules;  
266                          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");
267    
268                          $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 271  while (my ($database, $db_config) = each
271    
272                          $log->info("Using $normalize_path for normalization...");                          $log->info("Using $normalize_path for normalization...");
273    
274                            my $marc_fh;
275                            if (my $path = $normalize->{output}) {
276                                    open($marc_fh, '>', $path) ||
277                                            $log->logdie("can't open MARC output $path: $!");
278    
279                                    $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n");
280                            }
281    
282                          # reset position in database                          # reset position in database
283                          $input_db->seek(1);                          $input_db->seek(1);
284    
# Line 260  while (my ($database, $db_config) = each Line 305  while (my ($database, $db_config) = each
305                                          row => $row,                                          row => $row,
306                                          rules => $rules,                                          rules => $rules,
307                                          lookup => $lookup ? $lookup->lookup_hash : undef,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
308                                            marc_encoding => 'utf-8',
309                                  );                                  );
310    
311                                  $db->save_ds(                                  $db->save_ds(
# Line 272  while (my ($database, $db_config) = each Line 318  while (my ($database, $db_config) = each
318                                          id => $input->{name} . "/" . $mfn,                                          id => $input->{name} . "/" . $mfn,
319                                          ds => $ds,                                          ds => $ds,
320                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
321                                  ) if ($indexer);                                  ) if ($indexer && $ds);
322    
323                                    if ($marc_fh) {
324                                            my $marc = new MARC::Record;
325                                            $marc->encoding( 'utf-8' );
326                                            my @marc_fields = WebPAC::Normalize::_get_marc_fields();
327                                            if (! @marc_fields) {
328                                                    $log->warn("MARC record $mfn is empty, skipping");
329                                            } else {
330                                                    $marc->add_fields( @marc_fields );
331    
332                                                    if ($marc_lint) {
333                                                            $lint->check_record( $marc );
334                                                            my $err = join( "\n", $lint->warnings );
335                                                            $log->error("MARC lint detected warning on MFN $mfn\n",
336                                                                    "Original imput row: ",dump($row), "\n",
337                                                                    "Normalized MARC row: ",dump(@marc_fields), "\n",
338                                                                    "MARC lint warnings: ",$err,"\n"
339                                                            ) if ($err);
340                                                    }
341    
342                                                    if ($marc_dump) {
343                                                            $log->info("MARC record on MFN $mfn\n",
344                                                                    "Original imput row: ",dump($row), "\n",
345                                                                    "Normalized MARC row: ",dump(@marc_fields), "\n",
346                                                            );
347                                                    }
348    
349                                                    print $marc_fh $marc->as_usmarc;
350                                            }
351                                    }
352    
353                                  $total_rows++;                                  $total_rows++;
354                          }                          }
355    
356                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
357    
358                  };                          # close MARC file
359                            close($marc_fh) if ($marc_fh);
360    
361                    }
362    
363          }          }
364    
# Line 295  while (my ($database, $db_config) = each Line 374  while (my ($database, $db_config) = each
374          #          #
375          # add Hyper Estraier links to other databases          # add Hyper Estraier links to other databases
376          #          #
377          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
378                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
379                          if ($use_indexer eq 'hyperestraier') {                          if ($use_indexer eq 'hyperestraier') {
380                                  $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.559

  ViewVC Help
Powered by ViewVC 1.1.26