--- trunk/run.pl 2006/09/11 20:26:01 672 +++ trunk/run.pl 2006/09/25 12:51:17 699 @@ -7,6 +7,7 @@ use lib './lib'; use WebPAC::Common 0.02; +use WebPAC::Parser 0.04; use WebPAC::Lookup 0.03; use WebPAC::Input 0.11; use WebPAC::Store 0.03; @@ -14,7 +15,7 @@ use WebPAC::Output::TT; use WebPAC::Validate 0.06; use WebPAC::Output::MARC; -use YAML qw/LoadFile/; +use WebPAC::Config; use Getopt::Long; use File::Path; use Time::HiRes qw/time/; @@ -105,7 +106,7 @@ my $limit; my $clean = 0; -my $config = 'conf/config.yml'; +my $config_path; my $debug = 0; my $only_filter; my $stats = 0; @@ -119,21 +120,13 @@ my $log = _new WebPAC::Common()->_get_logger(); -my $hostname = `hostname`; -chomp($hostname); -$hostname =~ s/\..+$//; -if (-e "conf/$hostname.yml") { - $config = "conf/$hostname.yml"; - $log->info("using host configuration file: $config"); -} - GetOptions( "limit=i" => \$limit, "offset=i" => \$offset, "clean" => \$clean, "one=s" => \$only_filter, "only=s" => \$only_filter, - "config" => \$config, + "config" => \$config_path, "debug+" => \$debug, "stats" => \$stats, "validate=s" => \$validate_path, @@ -146,11 +139,11 @@ "merge" => \$merge, ); -$config = LoadFile($config); +my $config = new WebPAC::Config( path => $config_path ); #print "config = ",dump($config) if ($debug); -die "no databases in config file!\n" unless ($config->{databases}); +die "no databases in config file!\n" unless ($config->databases); $log->info( "-" x 79 ); @@ -171,7 +164,7 @@ ) if ($validate_path); -my $use_indexer = $config->{use_indexer} || 'hyperestraier'; +my $use_indexer = $config->use_indexer; if ($stats) { $log->debug("option --stats disables update of indexing engine..."); $use_indexer = undef; @@ -182,6 +175,10 @@ # disable indexing when creating marc $use_indexer = undef if ($marc_normalize); +# parse normalize files and create source files for lookup and normalization + +my $parser = new WebPAC::Parser( config => $config ); + my $total_rows = 0; my $start_t = time(); @@ -192,7 +189,7 @@ Proc::Queue::size($parallel); } -while (my ($database, $db_config) = each %{ $config->{databases} }) { +while (my ($database, $db_config) = each %{ $config->databases }) { my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); next if ($only_database && $database !~ m/$only_database/i); @@ -212,7 +209,7 @@ my $cfg_name = $use_indexer; $cfg_name =~ s/\-.*$//; - my $indexer_config = $config->{$cfg_name} || $log->logdie("can't find '$cfg_name' part in confguration"); + my $indexer_config = $config->get( $cfg_name ) || $log->logdie("can't find '$cfg_name' part in confguration"); $indexer_config->{database} = $database; $indexer_config->{clean} = $clean; $indexer_config->{label} = $db_config->{name}; @@ -232,8 +229,6 @@ use WebPAC::Output::EstraierNative; $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } ); - $use_indexer = 'hyperestraier'; - } elsif ($use_indexer eq 'kinosearch') { # open KinoSearch @@ -282,7 +277,7 @@ my $abs_path = abs_path($0); $abs_path =~ s#/[^/]*$#/#; - my $db_path = $config->{webpac}->{db_path} . '/' . $database; + my $db_path = $config->get('webpac')->{db_path} . '/' . $database; if ($clean) { $log->info("creating new database '$database' in $db_path"); @@ -311,25 +306,15 @@ $log->info("database $database doesn't have inputs defined"); } - my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; - foreach my $input (@inputs) { next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i)); my $type = lc($input->{type}); - 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(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs'))); - my $lookup; - if ($input->{lookup}) { - $lookup = new WebPAC::Lookup( - lookup_file => $input->{lookup}, - ); - delete( $input->{lookup} ); - } - - my $input_module = $config->{webpac}->{inputs}->{$type}; + my $input_module = $config->webpac('inputs')->{$type}; $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module", $input->{lookup} ? "lookup '$input->{lookup}'" : "" @@ -341,9 +326,16 @@ delete($input->{modify_file}); } + warn "parser->depends = ", dump( $parser->{depends} ); + warn "depends on: ", dump( $parser->depends($database, $input->{name}) ); + warn "lookup_create_rules = ", dump( $parser->lookup_create_rules($database, $input->{name}) ); + warn "parser->_lookup_create = ", dump( $parser->{_lookup_create} ); + + my $lookup; + my $input_db = new WebPAC::Input( module => $input_module, - encoding => $config->{webpac}->{webpac_encoding}, + encoding => $config->webpac('webpac_encoding'), limit => $limit || $input->{limit}, offset => $offset, lookup_coderef => sub { @@ -402,6 +394,10 @@ # reset position in database $input_db->seek(1); + # generate name of config key for indexer (strip everything after -) + my $indexer_config = $use_indexer; + $indexer_config =~ s/^(\w+)-?.*$/$1/g if ($indexer_config); + foreach my $pos ( 0 ... $input_db->size ) { my $row = $input_db->fetch || next; @@ -451,7 +447,7 @@ $indexer->add( id => $input->{name} . "/" . $mfn, ds => $ds, - type => $config->{$use_indexer}->{type}, + type => $config->get($indexer_config)->{type}, ) if ($indexer && $ds); if ($marc) {