/[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 540 by dpavlin, Thu Jun 29 15:29:41 2006 UTC revision 585 by dpavlin, Wed Jul 5 19:52:45 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;
10  use WebPAC::Lookup;  use WebPAC::Lookup;
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;
22  use MARC::Record;  use Data::Dump qw/dump/;
23    
24  =head1 NAME  =head1 NAME
25    
# Line 63  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    =item --marc-lint
75    
76    By default turned on if C<--marc-normalize> is used. You can disable lint
77    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    
85  =cut  =cut
# Line 76  my $debug = 0; Line 93  my $debug = 0;
93  my $only_filter;  my $only_filter;
94  my $stats = 0;  my $stats = 0;
95  my $validate_path;  my $validate_path;
96    my ($marc_normalize, $marc_output);
97    my $marc_lint = 1;
98    my $marc_dump = 0;
99    
100  GetOptions(  GetOptions(
101          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 84  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,
111            "marc-output=s" => \$marc_output,
112            "marc-lint!" => \$marc_lint,
113            "marc-dump!" => \$marc_dump,
114  );  );
115    
116  $config = LoadFile($config);  $config = LoadFile($config);
117    
118  print "config = ",Dumper($config) if ($debug);  print "config = ",dump($config) if ($debug);
119    
120  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
121    
# Line 111  if ($stats) { Line 135  if ($stats) {
135          $log->info("using $use_indexer indexing engine...");          $log->info("using $use_indexer indexing engine...");
136  }  }
137    
138    # disable indexing when creating marc
139    $use_indexer = undef if ($marc_normalize);
140    
141  my $total_rows = 0;  my $total_rows = 0;
142  my $start_t = time();  my $start_t = time();
143    
# Line 206  while (my ($database, $db_config) = each Line 233  while (my ($database, $db_config) = each
233    
234                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
235                          module => $input_module,                          module => $input_module,
236                          code_page => $config->{webpac}->{webpac_encoding},                          encoding => $config->{webpac}->{webpac_encoding},
237                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
238                          offset => $offset,                          offset => $offset,
239                          lookup => $lookup,                          lookup_coderef => sub {
240                                    my $rec = shift || return;
241                                    $lookup->add( $rec );
242                            },
243                          recode => $input->{recode},                          recode => $input->{recode},
244                          stats => $stats,                          stats => $stats,
245                  );                  );
# Line 224  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 235  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;                          my $marc = new WebPAC::Output::MARC(
275                          if (my $path = $normalize->{marc21}) {                                  path => $normalize->{output},
276                                  open($marc_fh, '>', $path) ||                                  lint => $marc_lint,
277                                          $log->logdie("can't open MARC output $path: $!");                                  dump => $marc_dump,
278                            ) if ($normalize->{output});
                                 $log->info("Creating MARC export file $path\n");  
                         }  
279    
280                          # reset position in database                          # reset position in database
281                          $input_db->seek(1);                          $input_db->seek(1);
# Line 264  while (my ($database, $db_config) = each Line 298  while (my ($database, $db_config) = each
298                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);                                          $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
299                                  }                                  }
300    
                                           
301                                  my $ds = WebPAC::Normalize::data_structure(                                  my $ds = WebPAC::Normalize::data_structure(
302                                          row => $row,                                          row => $row,
303                                          rules => $rules,                                          rules => $rules,
304                                          lookup => $lookup ? $lookup->lookup_hash : undef,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
305                                            marc_encoding => 'utf-8',
306                                  );                                  );
307    
308                                  $db->save_ds(                                  $db->save_ds(
# Line 283  while (my ($database, $db_config) = each Line 317  while (my ($database, $db_config) = each
317                                          type => $config->{$use_indexer}->{type},                                          type => $config->{$use_indexer}->{type},
318                                  ) if ($indexer && $ds);                                  ) if ($indexer && $ds);
319    
320                                  if ($marc_fh) {                                  if ($marc) {
321                                          my $marc = new MARC::Record;                                          my $i = 0;
322                                          $marc->add_fields( WebPAC::Normalize::_get_marc21_fields() );  
323                                          print $marc_fh $marc->as_usmarc;                                          while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) {
324                                                    $marc->add(
325                                                            id => $mfn . ( $i ? "/$i" : '' ),
326                                                            fields => $fields,
327                                                            leader => WebPAC::Normalize::marc_leader(),
328                                                            row => $row,
329                                                    );
330                                                    $i++;
331                                            }
332    
333                                            $log->info("Created $i instances of MFN $mfn\n") if ($i > 1);
334                                  }                                  }
335    
336                                  $total_rows++;                                  $total_rows++;
# Line 295  while (my ($database, $db_config) = each Line 339  while (my ($database, $db_config) = each
339                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);                          $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
340    
341                          # close MARC file                          # close MARC file
342                          close($marc_fh) if ($marc_fh);                          $marc->finish if ($marc);
343    
344                  }                  }
345    
# Line 313  while (my ($database, $db_config) = each Line 357  while (my ($database, $db_config) = each
357          #          #
358          # add Hyper Estraier links to other databases          # add Hyper Estraier links to other databases
359          #          #
360          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
361                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
362                          if ($use_indexer eq 'hyperestraier') {                          if ($use_indexer eq 'hyperestraier') {
363                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");                                  $log->info("saving link $database -> $link->{to} [$link->{credit}]");

Legend:
Removed from v.540  
changed lines
  Added in v.585

  ViewVC Help
Powered by ViewVC 1.1.26