11 |
|
|
12 |
=head1 VERSION |
=head1 VERSION |
13 |
|
|
14 |
Version 0.01 |
Version 0.04 |
15 |
|
|
16 |
=cut |
=cut |
17 |
|
|
18 |
our $VERSION = '0.01'; |
our $VERSION = '0.04'; |
19 |
|
|
20 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
21 |
|
|
82 |
db => $db_obj, |
db => $db_obj, |
83 |
lookup_regex => $lookup->regex, |
lookup_regex => $lookup->regex, |
84 |
lookup => $lookup_obj, |
lookup => $lookup_obj, |
85 |
|
prefix => 'foobar', |
86 |
); |
); |
87 |
|
|
88 |
Parametar C<filter> defines user supplied snippets of perl code which can |
Parametar C<filter> defines user supplied snippets of perl code which can |
89 |
be use with C<filter{...}> notation. |
be use with C<filter{...}> notation. |
90 |
|
|
91 |
|
C<prefix> is used to form filename for database record (to support multiple |
92 |
|
source files which are joined in one database). |
93 |
|
|
94 |
Recommended parametar C<lookup_regex> is used to enable parsing of lookups |
Recommended parametar C<lookup_regex> is used to enable parsing of lookups |
95 |
in structures. If you pass this parametar, you must also pass C<lookup> |
in structures. If you pass this parametar, you must also pass C<lookup> |
96 |
which is C<WebPAC::Lookup> object. |
which is C<WebPAC::Lookup> object. |
115 |
|
|
116 |
$log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); |
$log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); |
117 |
|
|
118 |
|
$log->warn("no prefix defined. please check that!") unless ($self->{'prefix'}); |
119 |
|
|
120 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
121 |
} |
} |
122 |
|
|
128 |
|
|
129 |
This structures are used to produce output. |
This structures are used to produce output. |
130 |
|
|
131 |
my @ds = $webpac->data_structure($rec); |
my $ds = $webpac->data_structure($rec); |
|
|
|
|
B<Note: historical oddity follows> |
|
|
|
|
|
This method will also set C<< $webpac->{'currnet_filename'} >> if there is |
|
|
C<< <filename> >> tag and C<< $webpac->{'headline'} >> if there is |
|
|
C<< <headline> >> tag. |
|
132 |
|
|
133 |
=cut |
=cut |
134 |
|
|
140 |
my $rec = shift; |
my $rec = shift; |
141 |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
142 |
|
|
143 |
|
$log->debug("data_structure rec = ", sub { Dumper($rec) }); |
144 |
|
|
145 |
|
$log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'})); |
146 |
|
|
147 |
|
my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); |
148 |
|
|
149 |
my $cache_file; |
my $cache_file; |
150 |
|
|
151 |
if ($self->{'db'}) { |
if ($self->{'db'}) { |
152 |
my @ds = $self->{'db'}->load_ds($rec); |
my $ds = $self->{'db'}->load_ds( id => $id, prefix => $self->{prefix} ); |
153 |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) }); |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) }); |
154 |
return @ds if ($#ds > 0); |
return $ds if ($ds); |
155 |
$log->debug("cache miss, creating"); |
$log->debug("cache miss, creating"); |
156 |
} |
} |
157 |
|
|
166 |
$self->{tags_by_order} = \@sorted_tags; |
$self->{tags_by_order} = \@sorted_tags; |
167 |
} |
} |
168 |
|
|
169 |
my @ds; |
my $ds; |
170 |
|
|
171 |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
172 |
|
|
201 |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
202 |
} |
} |
203 |
|
|
|
if ($field eq 'filename') { |
|
|
$self->{'current_filename'} = join('',@v); |
|
|
$log->debug("filename: ",$self->{'current_filename'}); |
|
|
} elsif ($field eq 'headline') { |
|
|
$self->{'headline'} .= join('',@v); |
|
|
$log->debug("headline: ",$self->{'headline'}); |
|
|
next; # don't return headline in data_structure! |
|
|
} |
|
|
|
|
204 |
# delimiter will join repeatable fields |
# delimiter will join repeatable fields |
205 |
if ($tag->{'delimiter'}) { |
if ($tag->{'delimiter'}) { |
206 |
@v = ( join($tag->{'delimiter'}, @v) ); |
@v = ( join($tag->{'delimiter'}, @v) ); |
207 |
} |
} |
208 |
|
|
209 |
# default types |
# default types |
210 |
my @types = qw(display swish); |
my @types = qw(display search); |
211 |
# override by type attribute |
# override by type attribute |
212 |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
213 |
|
|
240 |
|
|
241 |
# TODO: name_sigular, name_plural |
# TODO: name_sigular, name_plural |
242 |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
243 |
$row->{'name'} = $name ? $self->_x($name) : $field; |
my $row_name = $name ? $self->_x($name) : $field; |
244 |
|
|
245 |
# post-sort all values in field |
# post-sort all values in field |
246 |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
247 |
$log->warn("sort at field tag not implemented"); |
$log->warn("sort at field tag not implemented"); |
248 |
} |
} |
249 |
|
|
250 |
push @ds, $row; |
$ds->{$row_name} = $row; |
251 |
|
|
252 |
$log->debug("row $field: ",sub { Dumper($row) }); |
$log->debug("row $field: ",sub { Dumper($row) }); |
253 |
} |
} |
254 |
|
|
255 |
} |
} |
256 |
|
|
|
$log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'}); |
|
|
|
|
257 |
$self->{'db'}->save_ds( |
$self->{'db'}->save_ds( |
258 |
ds => \@ds, |
id => $id, |
259 |
current_filename => $self->{'current_filename'}, |
ds => $ds, |
260 |
headline => $self->{'headline'}, |
prefix => $self->{prefix}, |
261 |
) if ($self->{'db'}); |
) if ($self->{'db'}); |
262 |
|
|
263 |
$log->debug("ds: ", sub { Dumper(@ds) }); |
$log->debug("ds: ", sub { Dumper($ds) }); |
264 |
|
|
265 |
|
$log->logconfess("data structure returned is not array any more!") if wantarray; |
266 |
|
|
267 |
return @ds; |
return $ds; |
268 |
|
|
269 |
} |
} |
270 |
|
|
675 |
|
|
676 |
=cut |
=cut |
677 |
|
|
678 |
1; # End of WebPAC::DB |
1; # End of WebPAC::Normalize |