2 |
|
|
3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
use base 'WebPAC::Common'; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
|
|
8 |
=head1 NAME |
=head1 NAME |
11 |
|
|
12 |
=head1 VERSION |
=head1 VERSION |
13 |
|
|
14 |
Version 0.01 |
Version 0.02 |
15 |
|
|
16 |
=cut |
=cut |
17 |
|
|
18 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
19 |
|
|
20 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
21 |
|
|
79 |
return length($_); |
return length($_); |
80 |
}, ... |
}, ... |
81 |
}, |
}, |
82 |
db => $webpac_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 |
|
|
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 |
|
|
122 |
|
|
123 |
This structures are used to produce output. |
This structures are used to produce output. |
124 |
|
|
125 |
my @ds = $webpac->data_structure($rec); |
my $ds = $webpac->data_structure($rec); |
126 |
|
|
127 |
B<Note: historical oddity follows> |
B<Note: historical oddity follows> |
128 |
|
|
143 |
my $cache_file; |
my $cache_file; |
144 |
|
|
145 |
if ($self->{'db'}) { |
if ($self->{'db'}) { |
146 |
my @ds = $self->{'db'}->get_ds($rec); |
my $ds = $self->{'db'}->load_ds($rec); |
147 |
return @ds if (@ds); |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) }); |
148 |
|
return $ds if ($ds); |
149 |
|
$log->debug("cache miss, creating"); |
150 |
} |
} |
151 |
|
|
152 |
undef $self->{'currnet_filename'}; |
undef $self->{'currnet_filename'}; |
160 |
$self->{tags_by_order} = \@sorted_tags; |
$self->{tags_by_order} = \@sorted_tags; |
161 |
} |
} |
162 |
|
|
163 |
my @ds; |
my $ds; |
164 |
|
|
165 |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
166 |
|
|
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 |
|
|
210 |
} |
} |
211 |
|
|
212 |
# default types |
# default types |
213 |
my @types = qw(display swish); |
my @types = qw(display search); |
214 |
# override by type attribute |
# override by type attribute |
215 |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
216 |
|
|
243 |
|
|
244 |
# TODO: name_sigular, name_plural |
# TODO: name_sigular, name_plural |
245 |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
246 |
$row->{'name'} = $name ? $self->_x($name) : $field; |
my $row_name = $name ? $self->_x($name) : $field; |
247 |
|
|
248 |
# post-sort all values in field |
# post-sort all values in field |
249 |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
250 |
$log->warn("sort at field tag not implemented"); |
$log->warn("sort at field tag not implemented"); |
251 |
} |
} |
252 |
|
|
253 |
push @ds, $row; |
$ds->{$row_name} = $row; |
254 |
|
|
255 |
$log->debug("row $field: ",sub { Dumper($row) }); |
$log->debug("row $field: ",sub { Dumper($row) }); |
256 |
} |
} |
257 |
|
|
258 |
} |
} |
259 |
|
|
260 |
$self->{'db'}->put_gs( |
$log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'}); |
261 |
ds => \@ds, |
|
262 |
|
$self->{'db'}->save_ds( |
263 |
|
ds => $ds, |
264 |
current_filename => $self->{'current_filename'}, |
current_filename => $self->{'current_filename'}, |
265 |
headline => $self->{'headline'}, |
headline => $self->{'headline'}, |
266 |
) if ($self->{'db'}); |
) if ($self->{'db'}); |
267 |
|
|
268 |
return @ds; |
$log->debug("ds: ", sub { Dumper($ds) }); |
269 |
|
|
270 |
|
$log->logconfess("data structure returned is not array any more!") if wantarray; |
271 |
|
|
272 |
|
return $ds; |
273 |
|
|
274 |
} |
} |
275 |
|
|
465 |
} |
} |
466 |
# do we have lookups? |
# do we have lookups? |
467 |
if ($self->{'lookup'}) { |
if ($self->{'lookup'}) { |
468 |
return $self->lookup($format); |
if ($self->{'lookup'}->can('lookup')) { |
469 |
|
return $self->{'lookup'}->lookup($format); |
470 |
|
} else { |
471 |
|
$log->warn("Have lookup object but can't invoke lookup method"); |
472 |
|
} |
473 |
} else { |
} else { |
474 |
return $format; |
return $format; |
475 |
} |
} |
542 |
if ($sf && $$rec->{$f}->[$i]->{$sf}) { |
if ($sf && $$rec->{$f}->[$i]->{$sf}) { |
543 |
$$found++ if (defined($$found)); |
$$found++ if (defined($$found)); |
544 |
return $$rec->{$f}->[$i]->{$sf}; |
return $$rec->{$f}->[$i]->{$sf}; |
545 |
} elsif ($$rec->{$f}->[$i]) { |
} elsif (! $sf && $$rec->{$f}->[$i]) { |
546 |
$$found++ if (defined($$found)); |
$$found++ if (defined($$found)); |
547 |
# it still might have subfield, just |
# it still might have subfield, just |
548 |
# not specified, so we'll dump all |
# not specified, so we'll dump all |
555 |
} else { |
} else { |
556 |
return $$rec->{$f}->[$i]; |
return $$rec->{$f}->[$i]; |
557 |
} |
} |
558 |
|
} else { |
559 |
|
return ''; |
560 |
} |
} |
561 |
} else { |
} else { |
562 |
return ''; |
return ''; |
597 |
$log->debug("using format $name [$format] on $data to produce: $out"); |
$log->debug("using format $name [$format] on $data to produce: $out"); |
598 |
|
|
599 |
if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { |
if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { |
600 |
return $self->lookup($out); |
return $self->{'lookup'}->lookup($out); |
601 |
} else { |
} else { |
602 |
return $out; |
return $out; |
603 |
} |
} |