r1018@llin: dpavlin | 2006-09-26 12:20:52 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 26 Sep 2006 10:23:04 +0000 (10:23 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 26 Sep 2006 10:23:04 +0000 (10:23 +0000)
 correct creation of lookups (by database and input)

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@712 07558da8-63fa-0310-ba24-9fe276d99e06

conf/log.conf
conf/lookup/ffkk-arti.pl
lib/WebPAC/Normalize.pm
lib/WebPAC/Parser.pm
run.pl

index c796592..69c0c83 100644 (file)
@@ -7,7 +7,7 @@ log4perl.rootLogger=INFO, LOG, SCREEN
 
 # you can specify methods from WebPAC here also!
 #log4perl.logger.main=INFO
-#log4perl.logger.main=DEBUG
+log4perl.logger.main=DEBUG
 
 #log4perl.logger.WebPAC=DEBUG
 
index 104bd7b..f81d60c 100644 (file)
@@ -1,17 +1,17 @@
 
 marc('777','v',
        lookup(
-               sub { 'ffkk/perl' . rec('000') },
+               sub { 'ffkk/peri' . rec('000') },
                'ffkk','peri',
                sub { rec('11') }
        ) ||
        lookup(
-               sub { 'ffkk/perl' . rec('000') },
+               sub { 'ffkk/peri' . rec('000') },
                'ffkk','peri',
                sub { first(rec(200,'a')) . ' ' . first(rec('200','e')) },
        ) ||
        lookup(
-               sub { "ffkk/perl" . rec('000') },
+               sub { "ffkk/peri" . rec('000') },
                'ffkk','peri',
                sub { rec(200,'a') },
                sub { rec(900,'x') },
index 2bbdc37..6abf00c 100644 (file)
@@ -962,7 +962,7 @@ sub lookup {
 
 Save value into lookup.
 
-  save_into_lookup($key,sub {
+  save_into_lookup($database,$input,$key,sub {
        # code which produce one or more values 
   });
 
@@ -971,13 +971,15 @@ This function shouldn't be called directly, it's called from code created by L<W
 =cut
 
 sub save_into_lookup {
-       my ($k,$coderef) = @_;
-       die "save_into_lookup needs key" unless defined($k);
+       my ($database,$input,$key,$coderef) = @_;
+       die "save_into_lookup needs database" unless defined($database);
+       die "save_into_lookup needs input" unless defined($input);
+       die "save_into_lookup needs key" unless defined($key);
        die "save_into_lookup needs CODE" unless ( defined($coderef) && ref($coderef) eq 'CODE' );
        my $mfn = $rec->{'000'}->[0] || die "mfn not defined or zero";
        foreach my $v ( $coderef->() ) {
-               $lookup->{$k}->{$v}->{$mfn}++;
-               warn "# lookup $k $v $mfn saved\n" if ($debug > 1);
+               $lookup->{$database}->{$input}->{$key}->{$v}->{$mfn}++;
+               warn "# saved lookup $database/$input/$key [$v] $mfn\n"; #if ($debug > 1);
        }
 }
 
index d3d54d2..667a930 100644 (file)
@@ -296,13 +296,15 @@ sub _parse_lookups {
 
                        $log->debug("key = $key");
 
-                       my $create = "save_into_lookup('$key', $e[7] $e[8] );\n";
-
-                       $log->debug("create: $create");
-
                        return $self->_lookup_error("invalid database $e[3] in $path" ) unless $self->valid_database( $e[3] );
                        return $self->_lookup_error("invalid input $e[5] of database $e[3] in $path", ) unless $self->valid_database_input( $e[3], $e[5] );
 
+                       my $create = qq{
+                               save_into_lookup($e[3],$e[5],'$key', $e[7] $e[8] );
+                       };
+
+                       $log->debug("create: $create");
+
                        # save code to create this lookup
                        $self->{_lookup_create}->{ _q($e[3]) }->{ _q($e[5]) } .= $create;
                        $self->{_lookup_create_key}->{ _q($e[3]) }->{ _q($e[5]) }->{ _q($key) }++;
diff --git a/run.pl b/run.pl
index 93363eb..6b7311f 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -391,10 +391,12 @@ while (my ($database, $db_config) = each %{ $config->databases }) {
 
                my $lookup_data = WebPAC::Normalize::_get_lookup();
 
-               $log->debug("created following lookups: ", dump( $lookup_data ));
+               if (defined( $lookup_data->{$database}->{$input_name} )) {
+                       $log->debug("created following lookups: ", dump( $lookup_data ));
 
-               foreach my $key (keys %$lookup_data) {
-                       $store->save_lookup( $database, $input_name, $key, $lookup_data->{$key} );
+                       foreach my $key (keys %{ $lookup_data->{$database}->{$input_name} }) {
+                               $store->save_lookup( $database, $input_name, $key, $lookup_data->{$database}->{$input_name}->{$key} );
+                       }
                }
 
                my $report_fh;