1 package WebPAC::Input::ISIS;
7 use base qw/WebPAC::Input WebPAC::Common/;
12 WebPAC::Input::ISIS - support for CDS/ISIS source files
20 our $VERSION = '0.01';
25 my ($have_biblio_isis, $have_openisis) = (0,0);
27 eval "use Biblio::Isis 0.13;";
32 $have_openisis = 1 unless ($@);
37 Open CDS/ISIS, WinISIS or IsisMarc database using Biblio::Isis or OpenIsis
38 module and read all records to memory.
40 my $isis = new WebPAC::Input::ISIS();
41 $isis->open( filename => '/path/to/ISIS/ISIS' );
47 This function will read whole database in memory and produce lookups.
50 filename => '/data/ISIS/ISIS',
54 lookup => $lookup_obj,
57 By default, ISIS code page is assumed to be C<852>.
59 If optional parametar C<start_mfn> is set, this will be first MFN to read
60 from database (so you can skip beginning of your database if you need to).
62 If optional parametar C<limit_mfn> is set, it will read just 500 records
63 from database in example above.
65 Returns number of last record read into memory (size of database, really).
73 my $log = $self->_get_logger();
75 $log->logcroak("need filename") if (! $arg->{'filename'});
76 my $code_page = $arg->{'code_page'} || '852';
78 $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*'));
80 # store data in object
81 $self->{'isis_filename'} = $arg->{'filename'};
82 $self->{'isis_code_page'} = $code_page;
84 #$self->{'isis_code_page'} = $code_page;
86 # create Text::Iconv object
87 my $cp = Text::Iconv->new($code_page,$self->{'code_page'});
89 $log->info("reading ISIS database '",$arg->{'filename'},"'");
90 $log->debug("isis code page: $code_page");
92 my ($isis_db,$maxmfn);
95 $log->debug("using OpenIsis perl bindings");
96 $isis_db = OpenIsis::open($arg->{'filename'});
97 $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1;
98 } elsif ($have_biblio_isis) {
99 $log->debug("using Biblio::Isis");
101 $isis_db = new Biblio::Isis(
102 isisdb => $arg->{'filename'},
103 include_deleted => 1,
105 my $l = shift || return;
106 $l = $cp->convert($l);
110 $maxmfn = $isis_db->count;
113 $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");
118 $log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN.");
124 if (my $s = $self->{'start_mfn'}) {
125 $log->info("skipping to MFN $s");
128 $self->{'start_mfn'} = $startmfn;
131 $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn});
133 $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));
137 for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) {
139 $log->debug("mfn: $mfn\n");
143 if ($have_openisis) {
145 # read record using OpenIsis
146 my $row = OpenIsis::read( $isis_db, $mfn );
147 foreach my $k (keys %{$row}) {
149 foreach my $l (@{$row->{$k}}) {
150 $l = $cp->convert($l);
154 foreach my $t (split(/\^/,$l)) {
156 $val->{substr($t,0,1)} = substr($t,1);
162 push @{$rec->{$k}}, $val;
165 push @{$rec->{'000'}}, $mfn;
169 } elsif ($have_biblio_isis) {
170 $rec = $isis_db->to_hash($mfn);
172 $log->logdie("hum? implementation missing?");
175 $log->confess("record $mfn empty?") unless ($rec);
178 if ($self->{'low_mem'}) {
179 $self->{'db'}->put($mfn, $rec);
181 $self->{'data'}->{$mfn} = $rec;
185 $self->{'lookup'}->add( $rec ) if ($self->{'lookup'} && can($self->{'lookup'}->add));
187 $self->progress_bar($mfn,$maxmfn);
191 $self->{'current_mfn'} = -1;
192 $self->{'last_pcnt'} = 0;
194 $log->debug("max mfn: $maxmfn");
196 # store max mfn and return it.
197 return $self->{'max_mfn'} = $maxmfn;
202 Fetch next record from database. It will also displays progress bar.
204 my $rec = $isis->fetch;
206 Record from this function should probably go to C<data_structure> for
214 my $log = $self->_get_logger();
216 $log->logconfess("it seems that you didn't load database!") unless ($self->{'current_mfn'});
218 if ($self->{'current_mfn'} == -1) {
219 $self->{'current_mfn'} = $self->{'start_mfn'};
221 $self->{'current_mfn'}++;
224 my $mfn = $self->{'current_mfn'};
226 if ($mfn > $self->{'max_mfn'}) {
227 $self->{'current_mfn'} = $self->{'max_mfn'};
228 $log->debug("at EOF");
232 $self->progress_bar($mfn,$self->{'max_mfn'});
234 if ($self->{'low_mem'}) {
235 return $self->{'db'}->get($mfn);
237 return $self->{'data'}->{$mfn};
243 Returns current record number (MFN).
247 First record in database has position 1.
253 return $self->{'current_mfn'};
259 Returns number of records in database
267 return $self->{'max_mfn'};
272 Seek to specified MFN in file.
276 First record in database has position 1.
282 my $pos = shift || return;
284 my $log = $self->_get_logger();
287 $log->warn("seek before first record");
289 } elsif ($pos > $self->{'max_mfn'}) {
290 $log->warn("seek beyond last record");
291 $pos = $self->{'max_mfn'};
294 return $self->{'current_mfn'} = (($pos - 1) || -1);
299 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
301 =head1 COPYRIGHT & LICENSE
303 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
305 This program is free software; you can redistribute it and/or modify it
306 under the same terms as Perl itself.
310 1; # End of WebPAC::Input::ISIS