/[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 556 by dpavlin, Sat Jul 1 20:29:09 2006 UTC revision 588 by dpavlin, Fri Jul 7 21:47:13 2006 UTC
# Line 7  use File::Temp qw/tempdir/; Line 7  use File::Temp qw/tempdir/;
7  use lib './lib';  use lib './lib';
8    
9  use WebPAC::Common 0.02;  use WebPAC::Common 0.02;
10  use WebPAC::Lookup;  use WebPAC::Lookup 0.03;
11  use WebPAC::Input 0.03;  use WebPAC::Input 0.07;
12  use WebPAC::Store 0.03;  use WebPAC::Store 0.03;
13  use WebPAC::Normalize;  use WebPAC::Normalize 0.11;
14  use WebPAC::Output::TT;  use WebPAC::Output::TT;
15  use WebPAC::Validate;  use WebPAC::Validate;
16    use WebPAC::Output::MARC;
17  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
18  use Getopt::Long;  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;
 use MARC::Record 2.0;   # need 2.0 for utf-8 encoding see marcpm.sf.net  
 use MARC::Lint;  
22  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
23    
24  =head1 NAME  =head1 NAME
# Line 75  Optional path to output file Line 74  Optional path to output file
74  =item --marc-lint  =item --marc-lint
75    
76  By default turned on if C<--marc-normalize> is used. You can disable lint  By default turned on if C<--marc-normalize> is used. You can disable lint
77  messages with C<--no-arc-lint>.  messages with C<--no-marc-lint>.
78    
79    =item --marc-dump
80    
81    Force dump or input and marc record for debugging.
82    
83  =back  =back
84    
# Line 92  my $stats = 0; Line 95  my $stats = 0;
95  my $validate_path;  my $validate_path;
96  my ($marc_normalize, $marc_output);  my ($marc_normalize, $marc_output);
97  my $marc_lint = 1;  my $marc_lint = 1;
98    my $marc_dump = 0;
99    
100  GetOptions(  GetOptions(
101          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 100  GetOptions( Line 104  GetOptions(
104          "one=s" => \$only_filter,          "one=s" => \$only_filter,
105          "only=s" => \$only_filter,          "only=s" => \$only_filter,
106          "config" => \$config,          "config" => \$config,
107          "debug" => \$debug,          "debug+" => \$debug,
108          "stats" => \$stats,          "stats" => \$stats,
109          "validate=s" => \$validate_path,          "validate=s" => \$validate_path,
110          "marc-normalize=s" => \$marc_normalize,          "marc-normalize=s" => \$marc_normalize,
111          "marc-output=s" => \$marc_output,          "marc-output=s" => \$marc_output,
112          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
113            "marc-dump!" => \$marc_dump,
114  );  );
115    
116  $config = LoadFile($config);  $config = LoadFile($config);
# Line 139  my $start_t = time(); Line 144  my $start_t = time();
144  my @links;  my @links;
145  my $indexer;  my $indexer;
146    
 my $lint = new MARC::Lint if ($marc_lint);  
   
147  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
148    
149          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 218  while (my ($database, $db_config) = each Line 221  while (my ($database, $db_config) = each
221    
222                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
223    
224                  my $lookup = new WebPAC::Lookup(                  my $lookup;
225                          lookup_file => $input->{lookup},                  if ($input->{lookup}) {
226                  ) if ($input->{lookup});                          $lookup = new WebPAC::Lookup(
227                                    lookup_file => $input->{lookup},
228                            );
229                            delete( $input->{lookup} );
230                    }
231    
232                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
233    
# Line 230  while (my ($database, $db_config) = each Line 237  while (my ($database, $db_config) = each
237    
238                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
239                          module => $input_module,                          module => $input_module,
240                          code_page => $config->{webpac}->{webpac_encoding},                          encoding => $config->{webpac}->{webpac_encoding},
241                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
242                          offset => $offset,                          offset => $offset,
243                          lookup => $lookup,                          lookup_coderef => sub {
244                                    my $rec = shift || return;
245                                    $lookup->add( $rec );
246                            },
247                          recode => $input->{recode},                          recode => $input->{recode},
248                          stats => $stats,                          stats => $stats,
249                  );                  );
# Line 265  while (my ($database, $db_config) = each Line 275  while (my ($database, $db_config) = each
275    
276                          $log->info("Using $normalize_path for normalization...");                          $log->info("Using $normalize_path for normalization...");
277    
278                          my $marc_fh;                          my $marc = new WebPAC::Output::MARC(
279                          if (my $path = $normalize->{output}) {                                  path => $normalize->{output},
280                                  open($marc_fh, '>', $path) ||                                  lint => $marc_lint,
281                                          $log->logdie("can't open MARC output $path: $!");                                  dump => $marc_dump,
282                            ) if ($normalize->{output});
                                 $log->info("Creating MARC export file $path", $marc_lint ? ' (with lint)' : '', "\n");  
                         }  
283    
284                          # reset position in database                          # reset position in database
285                          $input_db->seek(1);                          $input_db->seek(1);
# Line 294  while (my ($database, $db_config) = each Line 302  while (my ($database, $db_config) = each
302                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
303                                  }                                  }
304    
                                           
305                                  my $ds = WebPAC::Normalize::data_structure(                                  my $ds = WebPAC::Normalize::data_structure(
306                                          row => $row,                                          row => $row,
307                                          rules => $rules,                                          rules => $rules,
# Line 314  while (my ($database, $db_config) = each Line 321  while (my ($database, $db_config) = each
321                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
322                                  ) if ($indexer && $ds);                                  ) if ($indexer && $ds);
323    
324                                  if ($marc_fh) {                                  if ($marc) {
325                                          my $marc = new MARC::Record;                                          my $i = 0;
326                                          $marc->encoding( 'utf-8' );  
327                                          my @marc_fields = WebPAC::Normalize::_get_marc_fields();                                          while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {
328                                          if (! @marc_fields) {                                                  $marc->add(
329                                                  $log->warn("MARC record $mfn is empty, skipping");                                                          id => $mfn . ( $i ? "/$i" : '' ),
330                                          } else {                                                          fields => $fields,
331                                                  $marc->add_fields( @marc_fields );                                                          leader => WebPAC::Normalize::marc_leader(),
332                                                  if ($marc_lint) {                                                          row => $row,
333                                                          $lint->check_record( $marc );                                                  );
334                                                          my $err = join( "\n", $lint->warnings );                                                  $i++;
                                                         $log->error("MARC lint detected warning on MFN $mfn\n",  
                                                                 "Original imput row: ",dump($row), "\n",  
                                                                 "Normalized MARC row: ",dump(@marc_fields), "\n",  
                                                                 "MARC lint warnings: ",$err,"\n"  
                                                         ) if ($err);  
                                                 }  
                                                 print $marc_fh $marc->as_usmarc;  
335                                          }                                          }
336    
337                                            $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
338                                  }                                  }
339    
340                                  $total_rows++;                                  $total_rows++;
# Line 341  while (my ($database, $db_config) = each Line 343  while (my ($database, $db_config) = each
343                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
344    
345                          # close MARC file                          # close MARC file
346                          close($marc_fh) if ($marc_fh);                          $marc->finish if ($marc);
347    
348                  }                  }
349    

Legend:
Removed from v.556  
changed lines
  Added in v.588

  ViewVC Help
Powered by ViewVC 1.1.26