13 |
|
|
14 |
use Data::Dumper; |
use Data::Dumper; |
15 |
|
|
16 |
|
my ($have_biblio_isis, $have_openisis) = (0,0); |
17 |
|
|
18 |
|
eval "use Biblio::Isis 0.13;"; |
19 |
|
unless ($@) { |
20 |
|
$have_biblio_isis = 1 |
21 |
|
} else { |
22 |
|
eval "use OpenIsis;"; |
23 |
|
$have_openisis = 1 unless ($@); |
24 |
|
} |
25 |
|
|
26 |
#my $LOOKUP_REGEX = '\[[^\[\]]+\]'; |
#my $LOOKUP_REGEX = '\[[^\[\]]+\]'; |
27 |
#my $LOOKUP_REGEX_SAVE = '\[([^\[\]]+)\]'; |
#my $LOOKUP_REGEX_SAVE = '\[([^\[\]]+)\]'; |
28 |
my $LOOKUP_REGEX = 'lookup{[^\{\}]+}'; |
my $LOOKUP_REGEX = 'lookup{[^\{\}]+}'; |
160 |
|
|
161 |
=head2 open_isis |
=head2 open_isis |
162 |
|
|
163 |
Open CDS/ISIS database using OpenIsis module and read all records to memory. |
Open CDS/ISIS, WinISIS or IsisMarc database using IsisDB or OpenIsis module |
164 |
|
and read all records to memory. |
165 |
|
|
166 |
$webpac->open_isis( |
$webpac->open_isis( |
167 |
filename => '/data/ISIS/ISIS', |
filename => '/data/ISIS/ISIS', |
209 |
$self->{'isis_filename'} = $arg->{'filename'}; |
$self->{'isis_filename'} = $arg->{'filename'}; |
210 |
$self->{'isis_code_page'} = $code_page; |
$self->{'isis_code_page'} = $code_page; |
211 |
|
|
|
use OpenIsis; |
|
|
|
|
212 |
#$self->{'isis_code_page'} = $code_page; |
#$self->{'isis_code_page'} = $code_page; |
213 |
|
|
214 |
# create Text::Iconv object |
# create Text::Iconv object |
217 |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
218 |
$log->debug("isis code page: $code_page"); |
$log->debug("isis code page: $code_page"); |
219 |
|
|
220 |
my $isis_db = OpenIsis::open($arg->{'filename'}); |
my ($isis_db,$maxmfn); |
221 |
|
|
222 |
|
if ($have_openisis) { |
223 |
|
$log->debug("using OpenIsis perl bindings"); |
224 |
|
$isis_db = OpenIsis::open($arg->{'filename'}); |
225 |
|
$maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; |
226 |
|
} elsif ($have_biblio_isis) { |
227 |
|
$log->debug("using Biblio::Isis"); |
228 |
|
use Biblio::Isis; |
229 |
|
$isis_db = new Biblio::Isis( |
230 |
|
isisdb => $arg->{'filename'}, |
231 |
|
include_deleted => 1, |
232 |
|
hash_filter => sub { |
233 |
|
my $l = shift || return; |
234 |
|
$l = $cp->convert($l); |
235 |
|
return $l; |
236 |
|
}, |
237 |
|
); |
238 |
|
$maxmfn = $isis_db->count; |
239 |
|
|
240 |
|
unless ($maxmfn) { |
241 |
|
$log->logwarn("no records in database ", $arg->{'filename'}, ", skipping..."); |
242 |
|
return; |
243 |
|
} |
244 |
|
|
245 |
|
} else { |
246 |
|
$log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN."); |
247 |
|
} |
248 |
|
|
249 |
|
|
|
my $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; |
|
250 |
my $startmfn = 1; |
my $startmfn = 1; |
251 |
|
|
252 |
if (my $s = $self->{'start_mfn'}) { |
if (my $s = $self->{'start_mfn'}) { |
258 |
|
|
259 |
$maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); |
$maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); |
260 |
|
|
261 |
$log->info("processing ",($maxmfn-$startmfn)." records..."); |
$log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis')); |
262 |
|
|
263 |
|
|
264 |
# read database |
# read database |
265 |
for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) { |
for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) { |
269 |
|
|
270 |
my $rec; |
my $rec; |
271 |
|
|
272 |
# read record |
if ($have_openisis) { |
273 |
my $row = OpenIsis::read( $isis_db, $mfn ); |
|
274 |
foreach my $k (keys %{$row}) { |
# read record using OpenIsis |
275 |
if ($k ne "mfn") { |
my $row = OpenIsis::read( $isis_db, $mfn ); |
276 |
foreach my $l (@{$row->{$k}}) { |
foreach my $k (keys %{$row}) { |
277 |
$l = $cp->convert($l); |
if ($k ne "mfn") { |
278 |
# has subfields? |
foreach my $l (@{$row->{$k}}) { |
279 |
my $val; |
$l = $cp->convert($l); |
280 |
if ($l =~ m/\^/) { |
# has subfields? |
281 |
foreach my $t (split(/\^/,$l)) { |
my $val; |
282 |
next if (! $t); |
if ($l =~ m/\^/) { |
283 |
$val->{substr($t,0,1)} = substr($t,1); |
foreach my $t (split(/\^/,$l)) { |
284 |
|
next if (! $t); |
285 |
|
$val->{substr($t,0,1)} = substr($t,1); |
286 |
|
} |
287 |
|
} else { |
288 |
|
$val = $l; |
289 |
} |
} |
|
} else { |
|
|
$val = $l; |
|
|
} |
|
290 |
|
|
291 |
push @{$rec->{$k}}, $val; |
push @{$rec->{$k}}, $val; |
292 |
|
} |
293 |
|
} else { |
294 |
|
push @{$rec->{'000'}}, $mfn; |
295 |
} |
} |
|
} else { |
|
|
push @{$rec->{'000'}}, $mfn; |
|
296 |
} |
} |
297 |
|
|
298 |
|
} elsif ($have_biblio_isis) { |
299 |
|
$rec = $isis_db->to_hash($mfn); |
300 |
|
} else { |
301 |
|
$log->logdie("hum? implementation missing?"); |
302 |
} |
} |
303 |
|
|
304 |
$log->confess("record $mfn empty?") unless ($rec); |
$log->confess("record $mfn empty?") unless ($rec); |
408 |
# reset on re-run |
# reset on re-run |
409 |
if ($p < $self->{'last_pcnt'}) { |
if ($p < $self->{'last_pcnt'}) { |
410 |
$self->{'last_pcnt'} = $p; |
$self->{'last_pcnt'} = $p; |
411 |
$self->{'last_t'} = time(); |
$self->{'start_t'} = time(); |
|
$self->{'last_curr'} = undef; |
|
412 |
} |
} |
413 |
|
|
|
$self->{'last_t'} ||= time(); |
|
|
|
|
414 |
if ($p != $self->{'last_pcnt'}) { |
if ($p != $self->{'last_pcnt'}) { |
415 |
|
|
|
my $last_curr = $self->{'last_curr'} || $curr; |
|
416 |
my $t = time(); |
my $t = time(); |
417 |
my $rate = ($curr - $last_curr) / (($t - $self->{'last_t'} || 1)); |
my $rate = ($curr / ($t - $self->{'start_t'} || 1)); |
418 |
my $eta = ($max-$curr) / ($rate || 1); |
my $eta = ($max-$curr) / ($rate || 1); |
419 |
printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$curr,"=" x ($p/3)."$p%>", $max, $rate, $self->fmt_time($eta)); |
printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$curr,"=" x ($p/3)."$p%>", $max, $rate, $self->fmt_time($eta)); |
420 |
$self->{'last_pcnt'} = $p; |
$self->{'last_pcnt'} = $p; |
|
$self->{'last_t'} = time(); |
|
421 |
$self->{'last_curr'} = $curr; |
$self->{'last_curr'} = $curr; |
422 |
} |
} |
423 |
print STDERR "\n" if ($p == 100); |
print STDERR "\n" if ($p == 100); |
938 |
|
|
939 |
if ($tag->{'sort'}) { |
if ($tag->{'sort'}) { |
940 |
@v = $self->sort_arr(@v); |
@v = $self->sort_arr(@v); |
|
$log->warn("sort within tag is usually not what you want!"); |
|
941 |
} |
} |
942 |
|
|
943 |
# use format? |
# use format? |