150 |
|
|
151 |
=head2 open_isis |
=head2 open_isis |
152 |
|
|
153 |
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 |
154 |
|
and read all records to memory. |
155 |
|
|
156 |
$webpac->open_isis( |
$webpac->open_isis( |
157 |
filename => '/data/ISIS/ISIS', |
filename => '/data/ISIS/ISIS', |
199 |
$self->{'isis_filename'} = $arg->{'filename'}; |
$self->{'isis_filename'} = $arg->{'filename'}; |
200 |
$self->{'isis_code_page'} = $code_page; |
$self->{'isis_code_page'} = $code_page; |
201 |
|
|
|
use OpenIsis; |
|
|
|
|
202 |
#$self->{'isis_code_page'} = $code_page; |
#$self->{'isis_code_page'} = $code_page; |
203 |
|
|
204 |
# create Text::Iconv object |
# create Text::Iconv object |
207 |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
208 |
$log->debug("isis code page: $code_page"); |
$log->debug("isis code page: $code_page"); |
209 |
|
|
210 |
my $isis_db = OpenIsis::open($arg->{'filename'}); |
my $use_openisis = 1; |
211 |
|
|
212 |
|
eval { use IsisDB 0.06; }; |
213 |
|
$use_openisis = 0 unless ($@); |
214 |
|
|
215 |
|
my ($isis_db,$maxmfn); |
216 |
|
|
217 |
|
if ($use_openisis) { |
218 |
|
use OpenIsis; |
219 |
|
$isis_db = OpenIsis::open($arg->{'filename'}); |
220 |
|
$maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; |
221 |
|
} else { |
222 |
|
$isis_db = new IsisDB( |
223 |
|
isisdb => $arg->{'filename'}, |
224 |
|
include_deleted => 1, |
225 |
|
hash_filter => sub { |
226 |
|
my $l = shift || return; |
227 |
|
$l = $cp->convert($l); |
228 |
|
return $l; |
229 |
|
}, |
230 |
|
); |
231 |
|
$maxmfn = $isis_db->{'maxmfn'}; |
232 |
|
} |
233 |
|
|
234 |
|
|
|
my $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; |
|
235 |
my $startmfn = 1; |
my $startmfn = 1; |
236 |
|
|
237 |
if (my $s = $self->{'start_mfn'}) { |
if (my $s = $self->{'start_mfn'}) { |
243 |
|
|
244 |
$maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); |
$maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); |
245 |
|
|
246 |
$log->info("processing ",($maxmfn-$startmfn)." records..."); |
$log->info("processing ",($maxmfn-$startmfn)." records using ",( $use_openisis ? 'OpenIsis' : 'IsisDB')); |
247 |
|
|
248 |
|
|
249 |
# read database |
# read database |
250 |
for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) { |
for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) { |
254 |
|
|
255 |
my $rec; |
my $rec; |
256 |
|
|
257 |
# read record |
if ($use_openisis) { |
258 |
my $row = OpenIsis::read( $isis_db, $mfn ); |
|
259 |
foreach my $k (keys %{$row}) { |
# read record using OpenIsis |
260 |
if ($k ne "mfn") { |
my $row = OpenIsis::read( $isis_db, $mfn ); |
261 |
foreach my $l (@{$row->{$k}}) { |
foreach my $k (keys %{$row}) { |
262 |
$l = $cp->convert($l); |
if ($k ne "mfn") { |
263 |
# has subfields? |
foreach my $l (@{$row->{$k}}) { |
264 |
my $val; |
$l = $cp->convert($l); |
265 |
if ($l =~ m/\^/) { |
# has subfields? |
266 |
foreach my $t (split(/\^/,$l)) { |
my $val; |
267 |
next if (! $t); |
if ($l =~ m/\^/) { |
268 |
$val->{substr($t,0,1)} = substr($t,1); |
foreach my $t (split(/\^/,$l)) { |
269 |
|
next if (! $t); |
270 |
|
$val->{substr($t,0,1)} = substr($t,1); |
271 |
|
} |
272 |
|
} else { |
273 |
|
$val = $l; |
274 |
} |
} |
|
} else { |
|
|
$val = $l; |
|
|
} |
|
275 |
|
|
276 |
push @{$rec->{$k}}, $val; |
push @{$rec->{$k}}, $val; |
277 |
|
} |
278 |
|
} else { |
279 |
|
push @{$rec->{'000'}}, $mfn; |
280 |
} |
} |
|
} else { |
|
|
push @{$rec->{'000'}}, $mfn; |
|
281 |
} |
} |
282 |
|
|
283 |
|
} else { |
284 |
|
$rec = $isis_db->to_hash($mfn); |
285 |
} |
} |
286 |
|
|
287 |
$log->confess("record $mfn empty?") unless ($rec); |
$log->confess("record $mfn empty?") unless ($rec); |
391 |
# reset on re-run |
# reset on re-run |
392 |
if ($p < $self->{'last_pcnt'}) { |
if ($p < $self->{'last_pcnt'}) { |
393 |
$self->{'last_pcnt'} = $p; |
$self->{'last_pcnt'} = $p; |
394 |
$self->{'last_t'} = time(); |
$self->{'start_t'} = time(); |
|
$self->{'last_curr'} = undef; |
|
395 |
} |
} |
396 |
|
|
|
$self->{'last_t'} ||= time(); |
|
|
|
|
397 |
if ($p != $self->{'last_pcnt'}) { |
if ($p != $self->{'last_pcnt'}) { |
398 |
|
|
|
my $last_curr = $self->{'last_curr'} || $curr; |
|
399 |
my $t = time(); |
my $t = time(); |
400 |
my $rate = ($curr - $last_curr) / (($t - $self->{'last_t'} || 1)); |
my $rate = ($curr / ($t - $self->{'start_t'} || 1)); |
401 |
my $eta = ($max-$curr) / ($rate || 1); |
my $eta = ($max-$curr) / ($rate || 1); |
402 |
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)); |
403 |
$self->{'last_pcnt'} = $p; |
$self->{'last_pcnt'} = $p; |
922 |
|
|
923 |
if ($tag->{'sort'}) { |
if ($tag->{'sort'}) { |
924 |
@v = $self->sort_arr(@v); |
@v = $self->sort_arr(@v); |
|
$log->warn("sort within tag is usually not what you want!"); |
|
925 |
} |
} |
926 |
|
|
927 |
# use format? |
# use format? |