/[webpac2]/trunk/lib/WebPAC/Normalize.pm
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/lib/WebPAC/Normalize.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 29 by dpavlin, Sun Jul 24 11:17:44 2005 UTC revision 64 by dpavlin, Tue Nov 15 16:56:44 2005 UTC
# Line 81  Create new normalisation object Line 81  Create new normalisation object
81          },          },
82          db => $db_obj,          db => $db_obj,
83          lookup_regex => $lookup->regex,          lookup_regex => $lookup->regex,
84            lookup => $lookup_obj,
85    );    );
86    
87  Parametar C<filter> defines user supplied snippets of perl code which can  Parametar C<filter> defines user supplied snippets of perl code which can
88  be use with C<filter{...}> notation.  be use with C<filter{...}> notation.
89    
90  Recommended parametar C<lookup_regex> is used to enable parsing of lookups  Recommended parametar C<lookup_regex> is used to enable parsing of lookups
91  in structures.  in structures. If you pass this parametar, you must also pass C<lookup>
92    which is C<WebPAC::Lookup> object.
93    
94  =cut  =cut
95    
# Line 96  sub new { Line 98  sub new {
98          my $self = {@_};          my $self = {@_};
99          bless($self, $class);          bless($self, $class);
100    
101            my $r = $self->{'lookup_regex'} ? 1 : 0;
102            my $l = $self->{'lookup'} ? 1 : 0;
103    
104            my $log = $self->_get_logger();
105    
106            # those two must be in pair
107            if ( ($r & $l) != ($r || $l) ) {
108                    my $log = $self->_get_logger();
109                    $log->logdie("lookup_regex and lookup must be in pair");
110            }
111    
112            $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup'));
113    
114          $self ? return $self : return undef;          $self ? return $self : return undef;
115  }  }
116    
# Line 156  sub data_structure { Line 171  sub data_structure {
171  #print "field $field [",$self->{'tag'},"] = ",Dumper($self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}});  #print "field $field [",$self->{'tag'},"] = ",Dumper($self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}});
172    
173                  foreach my $tag (@{$self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}}) {                  foreach my $tag (@{$self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}}) {
174                          my $format = $tag->{'value'} || $tag->{'content'};                          my $format;
175    
176                            $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH');
177                            $format = $tag->{'value'} || $tag->{'content'};
178    
179                          $log->debug("format: $format");                          $log->debug("format: $format");
180    
# Line 239  sub data_structure { Line 257  sub data_structure {
257    
258          }          }
259    
260            $log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'});
261    
262          $self->{'db'}->save_ds(          $self->{'db'}->save_ds(
263                  ds => \@ds,                  ds => \@ds,
264                  current_filename => $self->{'current_filename'},                  current_filename => $self->{'current_filename'},
# Line 443  sub fill_in { Line 463  sub fill_in {
463                  }                  }
464                  # do we have lookups?                  # do we have lookups?
465                  if ($self->{'lookup'}) {                  if ($self->{'lookup'}) {
466                          return $self->lookup($format);                          if ($self->{'lookup'}->can('lookup')) {
467                                    return $self->{'lookup'}->lookup($format);
468                            } else {
469                                    $log->warn("Have lookup object but can't invoke lookup method");
470                            }
471                  } else {                  } else {
472                          return $format;                          return $format;
473                  }                  }
# Line 516  sub get_data { Line 540  sub get_data {
540                  if ($sf && $$rec->{$f}->[$i]->{$sf}) {                  if ($sf && $$rec->{$f}->[$i]->{$sf}) {
541                          $$found++ if (defined($$found));                          $$found++ if (defined($$found));
542                          return $$rec->{$f}->[$i]->{$sf};                          return $$rec->{$f}->[$i]->{$sf};
543                  } elsif ($$rec->{$f}->[$i]) {                  } elsif (! $sf && $$rec->{$f}->[$i]) {
544                          $$found++ if (defined($$found));                          $$found++ if (defined($$found));
545                          # it still might have subfield, just                          # it still might have subfield, just
546                          # not specified, so we'll dump all                          # not specified, so we'll dump all
# Line 529  sub get_data { Line 553  sub get_data {
553                          } else {                          } else {
554                                  return $$rec->{$f}->[$i];                                  return $$rec->{$f}->[$i];
555                          }                          }
556                    } else {
557                            return '';
558                  }                  }
559          } else {          } else {
560                  return '';                  return '';
# Line 569  sub apply_format { Line 595  sub apply_format {
595          $log->debug("using format $name [$format] on $data to produce: $out");          $log->debug("using format $name [$format] on $data to produce: $out");
596    
597          if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) {          if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) {
598                  return $self->lookup($out);                  return $self->{'lookup'}->lookup($out);
599          } else {          } else {
600                  return $out;                  return $out;
601          }          }

Legend:
Removed from v.29  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26