5 |
_get_ds _clean_ds |
_get_ds _clean_ds |
6 |
|
|
7 |
tag search display |
tag search display |
8 |
|
marc21 |
9 |
|
|
10 |
rec1 rec2 rec |
rec1 rec2 rec |
11 |
regex prefix suffix surround |
regex prefix suffix surround |
12 |
first lookup join_with |
first lookup join_with |
17 |
|
|
18 |
#use base qw/WebPAC::Common/; |
#use base qw/WebPAC::Common/; |
19 |
use Data::Dumper; |
use Data::Dumper; |
20 |
|
use Encode qw/from_to/; |
21 |
|
|
22 |
=head1 NAME |
=head1 NAME |
23 |
|
|
25 |
|
|
26 |
=head1 VERSION |
=head1 VERSION |
27 |
|
|
28 |
Version 0.05 |
Version 0.06 |
29 |
|
|
30 |
=cut |
=cut |
31 |
|
|
32 |
our $VERSION = '0.05'; |
our $VERSION = '0.06'; |
33 |
|
|
34 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
35 |
|
|
42 |
C<perl -c normalize.pl>. |
C<perl -c normalize.pl>. |
43 |
|
|
44 |
Normalisation can generate multiple output normalized data. For now, supported output |
Normalisation can generate multiple output normalized data. For now, supported output |
45 |
types (on the left side of definition) are: C<tag>, C<display> and C<search>. |
types (on the left side of definition) are: C<tag>, C<display>, C<search> and |
46 |
|
C<marc21>. |
47 |
|
|
48 |
=head1 FUNCTIONS |
=head1 FUNCTIONS |
49 |
|
|
58 |
lookup => $lookup->lookup_hash, |
lookup => $lookup->lookup_hash, |
59 |
row => $row, |
row => $row, |
60 |
rules => $normalize_pl_config, |
rules => $normalize_pl_config, |
61 |
|
marc_encoding => 'utf-8', |
62 |
); |
); |
63 |
|
|
64 |
|
Options C<lookup>, C<row>, C<rules> and C<log> are mandatory while all |
65 |
|
other are optional. |
66 |
|
|
67 |
This function will B<die> if normalizastion can't be evaled. |
This function will B<die> if normalizastion can't be evaled. |
68 |
|
|
69 |
Since this function isn't exported you have to call it with |
Since this function isn't exported you have to call it with |
80 |
no strict 'subs'; |
no strict 'subs'; |
81 |
_set_lookup( $arg->{lookup} ); |
_set_lookup( $arg->{lookup} ); |
82 |
_set_rec( $arg->{row} ); |
_set_rec( $arg->{row} ); |
83 |
_clean_ds(); |
_clean_ds( %{ $arg } ); |
84 |
eval "$arg->{rules}"; |
eval "$arg->{rules}"; |
85 |
die "error evaling $arg->{rules}: $@\n" if ($@); |
die "error evaling $arg->{rules}: $@\n" if ($@); |
86 |
|
|
87 |
return _get_ds(); |
return _get_ds(); |
88 |
} |
} |
89 |
|
|
110 |
=cut |
=cut |
111 |
|
|
112 |
my $out; |
my $out; |
113 |
|
my $marc21; |
114 |
|
my $marc_encoding; |
115 |
|
|
116 |
sub _get_ds { |
sub _get_ds { |
117 |
return $out; |
return $out; |
126 |
=cut |
=cut |
127 |
|
|
128 |
sub _clean_ds { |
sub _clean_ds { |
129 |
|
my $a = {@_}; |
130 |
$out = undef; |
$out = undef; |
131 |
|
$marc21 = undef; |
132 |
|
$marc_encoding = $a->{marc_encoding}; |
133 |
} |
} |
134 |
|
|
135 |
=head2 _set_lookup |
=head2 _set_lookup |
146 |
$lookup = shift; |
$lookup = shift; |
147 |
} |
} |
148 |
|
|
149 |
|
=head2 _get_marc21_fields |
150 |
|
|
151 |
|
Get all fields defined by calls to C<marc21> |
152 |
|
|
153 |
|
$marc->add_fields( WebPAC::Normalize:_get_marc21_fields() ); |
154 |
|
|
155 |
|
=cut |
156 |
|
|
157 |
|
sub _get_marc21_fields { |
158 |
|
return @{$marc21}; |
159 |
|
} |
160 |
|
|
161 |
|
=head1 Functions to create C<data_structure> |
162 |
|
|
163 |
|
Those functions generally have to first in your normalization file. |
164 |
|
|
165 |
=head2 tag |
=head2 tag |
166 |
|
|
167 |
Define new tag for I<search> and I<display>. |
Define new tag for I<search> and I<display>. |
212 |
$out->{$name}->{search} = \@o; |
$out->{$name}->{search} = \@o; |
213 |
} |
} |
214 |
|
|
215 |
|
=head2 marc21 |
216 |
|
|
217 |
|
Save value for MARC field |
218 |
|
|
219 |
|
marc21('900','a', rec('200','a') ); |
220 |
|
|
221 |
|
=cut |
222 |
|
|
223 |
|
sub marc21 { |
224 |
|
my $f = shift or die "marc21 needs field"; |
225 |
|
die "marc21 field must be numer" unless ($f =~ /^\d+$/); |
226 |
|
|
227 |
|
my $sf = shift or die "marc21 needs subfield"; |
228 |
|
|
229 |
|
foreach (@_) { |
230 |
|
my $v = $_; # make var read-write for Encode |
231 |
|
next unless (defined($v) && $v !~ /^\s+$/); |
232 |
|
from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding); |
233 |
|
push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ]; |
234 |
|
} |
235 |
|
} |
236 |
|
|
237 |
|
=head1 Functions to extract data from input |
238 |
|
|
239 |
|
This function should be used inside functions to create C<data_structure> described |
240 |
|
above. |
241 |
|
|
242 |
=head2 rec1 |
=head2 rec1 |
243 |
|
|
244 |
Return all values in some field |
Return all values in some field |