42 |
], |
], |
43 |
); |
); |
44 |
|
|
45 |
|
Returns number of records produced. |
46 |
|
|
47 |
=cut |
=cut |
48 |
|
|
49 |
sub marc_template { |
sub marc_template { |
82 |
|
|
83 |
our $_template; |
our $_template; |
84 |
|
|
85 |
$_template->{fields_re} = { |
$_template->{isis}->{fields_re} = join('|', keys %$from_subfields ); |
86 |
isis => join('|', keys %$from_subfields ), |
$_template->{marc}->{fields_re} = join('|', keys %$to_subfields ); |
|
marc => join('|', keys %$to_subfields ), |
|
|
}; |
|
87 |
|
|
88 |
my @marc_out; |
my @marc_out; |
89 |
|
|
90 |
sub _parse_template { |
sub _parse_template { |
91 |
my ( $name, $templates ) = @_; |
my ( $name, $templates ) = @_; |
92 |
|
|
93 |
my $fields_re = $_template->{fields_re}->{ $name } || die "can't find $name in ",dump( $_template->{fields_re} ); |
my $fields_re = $_template->{$name}->{fields_re} || die "can't find $name in ",dump( $_template->{$name}->{fields_re} ); |
94 |
|
|
95 |
foreach my $template ( @{ $templates } ) { |
foreach my $template ( @{ $templates } ) { |
96 |
our $count = {}; |
our $count = {}; |
125 |
|
|
126 |
warn "### r = ",dump( $r ); |
warn "### r = ",dump( $r ); |
127 |
|
|
128 |
my ( $new_r, $from_count, $to_count ); |
my ( $from_mapping, $to_mapping, $from_count, $to_count ); |
129 |
foreach my $sf ( keys %{$r} ) { |
foreach my $sf ( keys %{$r} ) { |
130 |
# skip everything which isn't one char subfield (e.g. 'subfields') |
# skip everything which isn't one char subfield (e.g. 'subfields') |
131 |
next unless $sf =~ m/^\w$/; |
next unless $sf =~ m/^\w$/; |
134 |
die "can't find subfield rename for $sf/$nr in ", dump( $subfields_rename ); |
die "can't find subfield rename for $sf/$nr in ", dump( $subfields_rename ); |
135 |
warn "### rename $sf/$nr to ", dump( $rename_to->[$nr] ), $/; |
warn "### rename $sf/$nr to ", dump( $rename_to->[$nr] ), $/; |
136 |
my ( $to_sf, $to_nr ) = @{ $rename_to->[$nr] }; |
my ( $to_sf, $to_nr ) = @{ $rename_to->[$nr] }; |
137 |
$new_r->{ $to_sf }->[ $to_nr ] = [ $sf => $nr ]; |
$from_mapping->{ $sf }->[ $nr ] = [ $to_sf => $to_nr ]; |
138 |
|
$to_mapping->{ $to_sf }->[ $to_nr ] = [ $sf => $nr ]; |
139 |
|
|
140 |
$to_count->{ $to_sf }++; |
$to_count->{ $to_sf }++; |
141 |
} |
} |
142 |
|
|
143 |
warn "### new_r = ",dump( $new_r ); |
warn "### to_mapping = ",dump( $to_mapping ); |
144 |
|
|
145 |
my $count_key = { |
my $count_key = { |
146 |
from => dump( $from_count ), |
from => dump( $from_count ), |
154 |
# this defines order of traversal |
# this defines order of traversal |
155 |
foreach ( qw/isis:from marc:to/ ) { |
foreach ( qw/isis:from marc:to/ ) { |
156 |
my ($name,$count_name) = split(/:/); |
my ($name,$count_name) = split(/:/); |
|
warn "## traverse $name $count_name\n"; |
|
157 |
|
|
158 |
my $ckey = $count_key->{$count_name} || die "can't find count_key $count_name in ",dump( $count_key ); |
my $ckey = $count_key->{$count_name} || die "can't find count_key $count_name in ",dump( $count_key ); |
159 |
|
|
160 |
my $template = $_template->{$name}->{pos}->{ $ckey } || next; |
my $template = $_template->{$name}->{pos}->{ $ckey } || next; |
161 |
$processed_templates++; |
$processed_templates++; |
162 |
|
|
163 |
warn "### selected template: |$template|\n"; |
warn "### traverse $name $count_name selected template: |$template|\n"; |
164 |
|
|
165 |
our $fill_in = {}; |
our $fill_in = {}; |
166 |
|
|
172 |
my ( $name, $r, $sf, $nr ) = @_; |
my ( $name, $r, $sf, $nr ) = @_; |
173 |
my ( $from_sf, $from_nr, $v ); |
my ( $from_sf, $from_nr, $v ); |
174 |
if ( $name eq 'marc' ) { |
if ( $name eq 'marc' ) { |
175 |
( $from_sf, $from_nr ) = @{ $new_r->{$sf}->[$nr] }; |
( $from_sf, $from_nr ) = @{ $to_mapping->{$sf}->[$nr] }; |
176 |
} else { |
} else { |
177 |
( $from_sf, $from_nr ) = ( $sf, $nr ); |
( $from_sf, $from_nr ) = ( $sf, $nr ); |
178 |
} |
} |
188 |
die "requested subfield $from_sf/$from_nr but it's ",dump( $v ); |
die "requested subfield $from_sf/$from_nr but it's ",dump( $v ); |
189 |
} |
} |
190 |
} |
} |
191 |
my $fields_re = $_template->{fields_re}->{ $name } || die "can't find $name in ",dump( $_template->{fields_re} ); |
my $fields_re = $_template->{$name}->{fields_re} || die "can't find $name in ",dump( $_template->{$name}->{fields_re} ); |
192 |
warn "#### $sf <<<< $fields_re\n"; |
warn "#### $sf <<<< $fields_re\n"; |
193 |
$sf =~ s/($fields_re)(\d+)/fill_in($name,$r,$1,$2)/ge; |
$sf =~ s/($fields_re)(\d+)/fill_in($name,$r,$1,$2)/ge; |
194 |
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/; |
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/; |
196 |
|
|
197 |
warn "## template: |$template|\n## _template->$name = ",dump( $_template->{$name} ); |
warn "## template: |$template|\n## _template->$name = ",dump( $_template->{$name} ); |
198 |
|
|
|
$sf_pos = $#m; |
|
|
|
|
199 |
foreach my $sf ( @{ $_template->{$name}->{order}->{$template} } ) { |
foreach my $sf ( @{ $_template->{$name}->{order}->{$template} } ) { |
200 |
my ( $sf, $nr ) = @$sf; |
my ( $sf, $nr ) = @$sf; |
201 |
my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr"; |
my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr"; |
202 |
|
if ( $name eq 'isis') { |
203 |
|
( $sf, $nr ) = @{ $from_mapping->{$sf}->[$nr] }; |
204 |
|
} |
205 |
warn "++ $sf/$nr |$v|\n"; |
warn "++ $sf/$nr |$v|\n"; |
206 |
push @$m, ( $sf, $v ); |
push @$m, ( $sf, $v ); |
207 |
} |
} |
216 |
} |
} |
217 |
|
|
218 |
|
|
219 |
warn "### marc_template produced following MARC records: ",dump( @marc_out ); |
my $recs = 0; |
220 |
|
|
221 |
foreach my $marc ( @marc_out ) { |
foreach my $marc ( @marc_out ) { |
222 |
warn "+++ ",dump( $marc ); |
warn "+++ ",dump( $marc ),$/; |
223 |
WebPAC::Normalize::_marc_push( $marc ); |
WebPAC::Normalize::_marc_push( $marc ); |
224 |
|
$recs++; |
225 |
} |
} |
226 |
|
|
227 |
|
warn "### marc_template produced $recs MARC records: ",dump( @marc_out ), $/; |
228 |
} |
} |
229 |
|
|
230 |
1; |
1; |