9 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
10 |
use WebPAC::Parser 0.08; |
use WebPAC::Parser 0.08; |
11 |
use WebPAC::Input 0.16; |
use WebPAC::Input 0.16; |
12 |
use WebPAC::Store 0.14; |
use WebPAC::Store 0.15; |
13 |
use WebPAC::Normalize 0.22; |
use WebPAC::Normalize 0.22; |
14 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
15 |
use WebPAC::Validate 0.11; |
use WebPAC::Validate 0.11; |
133 |
"clean" => \$clean, |
"clean" => \$clean, |
134 |
"one=s" => \$only_filter, |
"one=s" => \$only_filter, |
135 |
"only=s" => \$only_filter, |
"only=s" => \$only_filter, |
136 |
"config" => \$config_path, |
"config=s" => \$config_path, |
137 |
"debug+" => \$debug, |
"debug+" => \$debug, |
138 |
"stats" => \$stats, |
"stats" => \$stats, |
139 |
"validate=s" => \$validate_path, |
"validate=s" => \$validate_path, |
153 |
|
|
154 |
my $config = new WebPAC::Config( path => $config_path ); |
my $config = new WebPAC::Config( path => $config_path ); |
155 |
|
|
156 |
|
WebPAC::Normalize::_debug( $debug - 1 ) if $debug > 1; |
157 |
|
|
158 |
#print "config = ",dump($config) if ($debug); |
#print "config = ",dump($config) if ($debug); |
159 |
|
|
160 |
die "no databases in config file!\n" unless ($config->databases); |
die "no databases in config file!\n" unless ($config->databases); |
179 |
|
|
180 |
my $validate; |
my $validate; |
181 |
$validate = new WebPAC::Validate( |
$validate = new WebPAC::Validate( |
|
path => $validate_path, |
|
182 |
delimiters => $config->webpac('delimiters'), |
delimiters => $config->webpac('delimiters'), |
|
delimiters_path => $validate_delimiters_path, |
|
183 |
) if ($validate_path || $validate_delimiters_path); |
) if ($validate_path || $validate_delimiters_path); |
184 |
|
|
185 |
my $use_indexer = $config->use_indexer; |
my $use_indexer = $config->use_indexer; |
187 |
if ($stats) { |
if ($stats) { |
188 |
$log->debug("disabled indexing for stats collection"); |
$log->debug("disabled indexing for stats collection"); |
189 |
$use_indexer = undef; |
$use_indexer = undef; |
190 |
} else { |
} elsif ( $use_indexer ) { |
191 |
$log->info("using $use_indexer indexing engine..."); |
$log->info("using $use_indexer indexing engine..."); |
192 |
} |
} |
193 |
|
|
194 |
# parse normalize files and create source files for lookup and normalization |
# parse normalize files and create source files for lookup and normalization |
195 |
|
|
196 |
my $parser = new WebPAC::Parser( config => $config ); |
my ($only_database,$only_input) = split(m#/#, $only_filter) if $only_filter; |
197 |
|
|
198 |
|
my $parser = new WebPAC::Parser( |
199 |
|
config => $config, |
200 |
|
only_database => $only_database, |
201 |
|
only_input => $only_input, |
202 |
|
); |
203 |
|
|
204 |
my $total_rows = 0; |
my $total_rows = 0; |
205 |
my $start_t = time(); |
my $start_t = time(); |
220 |
return $c; |
return $c; |
221 |
} |
} |
222 |
|
|
223 |
while (my ($database, $db_config) = each %{ $config->databases }) { |
foreach my $database ( sort keys %{ $config->databases } ) { |
224 |
|
my $db_config = $config->databases->{$database}; |
225 |
|
|
|
my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); |
|
226 |
next if ($only_database && $database !~ m/$only_database/i); |
next if ($only_database && $database !~ m/$only_database/i); |
227 |
|
|
228 |
if ($parallel) { |
if ($parallel) { |
251 |
if ($use_indexer eq 'hyperestraier') { |
if ($use_indexer eq 'hyperestraier') { |
252 |
|
|
253 |
# open Hyper Estraier database |
# open Hyper Estraier database |
254 |
use WebPAC::Output::Estraier '0.10'; |
require WebPAC::Output::Estraier; |
255 |
$indexer = new WebPAC::Output::Estraier( %{ $indexer_config } ); |
$indexer = new WebPAC::Output::Estraier( %{ $indexer_config } ); |
256 |
|
|
257 |
} elsif ($use_indexer eq 'hyperestraier-native') { |
} elsif ($use_indexer eq 'hyperestraier-native') { |
258 |
|
|
259 |
# open Hyper Estraier database |
# open Hyper Estraier database |
260 |
use WebPAC::Output::EstraierNative; |
require WebPAC::Output::EstraierNative; |
261 |
$indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } ); |
$indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } ); |
262 |
|
|
263 |
} elsif ($use_indexer eq 'kinosearch') { |
} elsif ($use_indexer eq 'kinosearch') { |
264 |
|
|
265 |
# open KinoSearch |
die "no longer supported"; |
|
use WebPAC::Output::KinoSearch; |
|
|
$indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path}); |
|
|
$indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); |
|
266 |
|
|
267 |
} else { |
} else { |
268 |
$log->logdie("unknown use_indexer: $use_indexer"); |
$log->logdie("unknown use_indexer: $use_indexer"); |
269 |
} |
} |
270 |
|
|
271 |
$log->logide("can't continue without valid indexer") unless ($indexer); |
$log->logdie("can't continue without valid indexer") unless ($indexer); |
272 |
} |
} |
273 |
|
|
274 |
|
|
302 |
# |
# |
303 |
# now WebPAC::Store |
# now WebPAC::Store |
304 |
# |
# |
305 |
my $abs_path = abs_path($0); |
my $store = new WebPAC::Store({ |
306 |
$abs_path =~ s#/[^/]*$#/#; |
debug => $debug, |
307 |
|
}); |
308 |
|
|
|
my $db_path = $config->webpac('db_path'); |
|
309 |
|
|
310 |
if ($clean) { |
# |
311 |
$log->info("creating new database '$database' in $db_path"); |
# prepare output |
312 |
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
# |
313 |
} else { |
my @outputs = force_array( $db_config->{output}, sub { |
314 |
$log->info("working on database '$database' in $db_path"); |
$log->error("Database $database doesn't have any outputs defined. Do you want to remove it from configuration?" ); |
315 |
} |
} ); |
316 |
|
|
317 |
my $store = new WebPAC::Store( |
my @output_modules; |
318 |
path => $db_path, |
|
319 |
debug => $debug, |
foreach my $output ( @outputs ) { |
320 |
); |
|
321 |
|
#warn '## output = ',dump( $output ); |
322 |
|
|
323 |
|
my $module = $output->{module} || $log->logdie("need module in output section of $database"); |
324 |
|
$module = 'WebPAC::Output::' . $module unless $module =~ m/::/; |
325 |
|
|
326 |
|
$log->debug("loading output module $module"); |
327 |
|
eval "require $module"; |
328 |
|
|
329 |
|
# add database to arugemnts for output filter |
330 |
|
$output->{database} = $database; |
331 |
|
|
332 |
|
$log->debug("calling $module->new(",dump( $output ),")"); |
333 |
|
my $out = new $module->new( $output ); |
334 |
|
if ( $out->init ) { |
335 |
|
push @output_modules, $out; |
336 |
|
} else { |
337 |
|
$log->warn("SKIPPED $module"); |
338 |
|
} |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
# |
# |
343 |
# now, iterate through input formats |
# now, iterate through input formats |
344 |
# |
# |
345 |
|
|
346 |
my @inputs; |
|
347 |
if (ref($db_config->{input}) eq 'ARRAY') { |
my @inputs = force_array( $db_config->{input}, sub { |
|
@inputs = @{ $db_config->{input} }; |
|
|
} elsif ($db_config->{input}) { |
|
|
push @inputs, $db_config->{input}; |
|
|
} else { |
|
348 |
$log->info("database $database doesn't have inputs defined"); |
$log->info("database $database doesn't have inputs defined"); |
349 |
} |
} ); |
350 |
|
|
351 |
foreach my $input (@inputs) { |
foreach my $input (@inputs) { |
352 |
|
|
356 |
|
|
357 |
my $type = lc($input->{type}); |
my $type = lc($input->{type}); |
358 |
|
|
359 |
die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs'))); |
# FIXME check if input module exists |
360 |
|
my $input_module = $input->{module}; |
361 |
|
|
362 |
my $input_module = $config->webpac('inputs')->{$type}; |
if ( ! $input_module ) { |
363 |
|
if ( grep(/$type/, $config->webpac('inputs')) ) { |
364 |
|
$input_module = $config->webpac('inputs')->{$type}; |
365 |
|
} else { |
366 |
|
$log->logdie("I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!" ); |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
my @lookups = $parser->have_lookup_create($database, $input); |
my @lookups = $parser->have_lookup_create($database, $input); |
371 |
|
|
372 |
$log->info("working on input '$input_name' in $input->{path} [type: $input->{type}] using $input_module", |
$log->info("working on $database/$input_name with $input_module on $input->{path}", |
373 |
@lookups ? " creating lookups: ".join(", ", @lookups) : "" |
@lookups ? " creating lookups: ".join(", ", @lookups) : "" |
374 |
); |
); |
375 |
|
|
388 |
stats => $stats, |
stats => $stats, |
389 |
modify_records => $input->{modify_records}, |
modify_records => $input->{modify_records}, |
390 |
modify_file => $input->{modify_file}, |
modify_file => $input->{modify_file}, |
391 |
|
input_config => $input, |
392 |
); |
); |
393 |
$log->logdie("can't create input using $input_module") unless ($input); |
$log->logdie("can't create input using $input_module") unless ($input); |
394 |
|
|
473 |
print $report_fh "Report for database '$database' input '$input_name' records ", |
print $report_fh "Report for database '$database' input '$input_name' records ", |
474 |
$offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n"; |
$offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n"; |
475 |
$log->info("Generating report file $path"); |
$log->info("Generating report file $path"); |
476 |
|
|
477 |
|
if ( $validate ) { |
478 |
|
$validate->read_validate_file( $validate->fill_in( $validate_path, database => $database, input => $input_name ) ) if ( $validate_path ); |
479 |
|
$validate->read_validate_delimiters_file( $validate->fill_in( $validate_delimiters_path, database => $database, input => $input_name ) ) if ( $validate_delimiters_path ); |
480 |
|
} |
481 |
} |
} |
482 |
|
|
483 |
my $marc; |
my $marc; |
525 |
} |
} |
526 |
|
|
527 |
|
|
528 |
|
# setup input name for all output filters |
529 |
|
foreach my $out ( @output_modules ) { |
530 |
|
if ( $out->can('input') ) { |
531 |
|
$out->input( $input_name ); |
532 |
|
} else { |
533 |
|
$log->warn("output filter ",ref($out)," doesn't support input name"); |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
foreach my $pos ( 0 ... $input_db->size ) { |
foreach my $pos ( 0 ... $input_db->size ) { |
539 |
|
|
540 |
my $row = $input_db->fetch || next; |
my $row = $input_db->fetch || next; |
543 |
|
|
544 |
my $mfn = $row->{'000'}->[0]; |
my $mfn = $row->{'000'}->[0]; |
545 |
|
|
546 |
if (! $mfn || $mfn !~ m#^\d+$#) { |
if (! $mfn || $mfn !~ m{^\d+$}) { |
547 |
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
548 |
$mfn = $pos; |
$mfn = $pos; |
549 |
push @{ $row->{'000'} }, $pos; |
push @{ $row->{'000'} }, $pos; |
567 |
marc_encoding => 'utf-8', |
marc_encoding => 'utf-8', |
568 |
load_row_coderef => sub { |
load_row_coderef => sub { |
569 |
my ($database,$input,$mfn) = @_; |
my ($database,$input,$mfn) = @_; |
570 |
|
#warn "### load_row($database,$input,$mfn) from data_structure\n"; |
571 |
return $store->load_row( |
return $store->load_row( |
572 |
database => $database, |
database => $database, |
573 |
input => $input, |
input => $input, |
576 |
}, |
}, |
577 |
); |
); |
578 |
|
|
579 |
$log->debug("ds = ", sub { dump($ds) }) if ($ds); |
$log->debug("ds = ", sub { dump($ds) }); |
580 |
|
|
581 |
|
if ( $ds ) { |
582 |
|
|
583 |
$store->save_ds( |
$store->save_ds( |
584 |
database => $database, |
database => $database, |
585 |
input => $input_name, |
input => $input_name, |
586 |
id => $mfn, |
id => $mfn, |
587 |
ds => $ds, |
ds => $ds, |
588 |
) if ($ds && !$stats); |
) if !$stats; |
589 |
|
|
590 |
$indexer->add( |
$indexer->add( |
591 |
id => "${input_name}/${mfn}", |
id => "${input_name}/${mfn}", |
592 |
ds => $ds, |
ds => $ds, |
593 |
type => $config->get($indexer_config)->{type}, |
type => $config->get($indexer_config)->{type}, |
594 |
) if ($indexer && $ds); |
) if $indexer; |
595 |
|
|
596 |
|
foreach my $out ( @output_modules ) { |
597 |
|
$out->add( $mfn, $ds ) if $out->can('add'); |
598 |
|
} |
599 |
|
|
600 |
|
} else { |
601 |
|
$log->warn("record $pos didn't produce any output after normalization rules!") unless $marc; |
602 |
|
} |
603 |
|
|
604 |
if ($marc) { |
if ($marc) { |
605 |
my $i = 0; |
my $i = 0; |
606 |
|
|
607 |
while (my $fields = WebPAC::Normalize::_get_marc_fields( fetch_next => 1 ) ) { |
while (my $fields = WebPAC::Normalize::MARC::_get_marc_fields( fetch_next => 1 ) ) { |
608 |
$marc->add( |
$marc->add( |
609 |
id => $mfn . ( $i ? "/$i" : '' ), |
id => $mfn . ( $i ? "/$i" : '' ), |
610 |
fields => $fields, |
fields => $fields, |
611 |
leader => WebPAC::Normalize::_get_marc_leader(), |
leader => WebPAC::Normalize::MARC::_get_marc_leader(), |
612 |
row => $row, |
row => $row, |
613 |
); |
); |
614 |
$i++; |
$i++; |
616 |
|
|
617 |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
$log->info("Created $i instances of MFN $mfn\n") if ($i > 1); |
618 |
} |
} |
619 |
|
|
620 |
} |
} |
621 |
|
|
622 |
if ($validate) { |
if ($validate) { |
647 |
|
|
648 |
eval { $indexer->finish } if ($indexer && $indexer->can('finish')); |
eval { $indexer->finish } if ($indexer && $indexer->can('finish')); |
649 |
|
|
650 |
|
foreach my $out ( @output_modules ) { |
651 |
|
$out->finish if $out->can('finish'); |
652 |
|
} |
653 |
|
|
654 |
my $dt = time() - $start_t; |
my $dt = time() - $start_t; |
655 |
$log->info("$total_rows records ", $indexer ? "indexed " : "", |
$log->info("$total_rows records ", $indexer ? "indexed " : "", |
656 |
sprintf("in %.2f sec [%.2f rec/sec]", |
sprintf("in %.2f sec [%.2f rec/sec]", |
674 |
} |
} |
675 |
|
|
676 |
# save new delimiters if needed |
# save new delimiters if needed |
677 |
$validate->save_delimiters_templates if ( $validate ); |
$validate->save_delimiters_templates if ( $validate_delimiters_path ); |
678 |
|
|
679 |
# |
# |
680 |
# handle links or merge after indexing |
# handle links or merge after indexing |