1 package WebPAC::Input::ISIS;
7 use base qw/WebPAC::Input WebPAC::Common/;
11 WebPAC::Input::ISIS - support for CDS/ISIS source files
19 our $VERSION = '0.01';
24 my ($have_biblio_isis, $have_openisis) = (0,0);
26 eval "use Biblio::Isis 0.13;";
31 $have_openisis = 1 unless ($@);
36 Open CDS/ISIS, WinISIS or IsisMarc database using Biblio::Isis or OpenIsis
37 module and read all records to memory.
39 my $isis = new WebPAC::Input::ISIS();
40 $isis->open( filename => '/path/to/ISIS/ISIS' );
46 This function will read whole database in memory and produce lookups.
49 filename => '/data/ISIS/ISIS',
53 lookup => $lookup_obj,
56 By default, ISIS code page is assumed to be C<852>.
58 If optional parametar C<start_mfn> is set, this will be first MFN to read
59 from database (so you can skip beginning of your database if you need to).
61 If optional parametar C<limit_mfn> is set, it will read just 500 records
62 from database in example above.
64 Returns number of last record read into memory (size of database, really).
72 my $log = $self->_get_logger();
74 $log->logcroak("need filename") if (! $arg->{'filename'});
75 my $code_page = $arg->{'code_page'} || '852';
77 $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*'));
79 # store data in object
80 $self->{'isis_filename'} = $arg->{'filename'};
81 $self->{'isis_code_page'} = $code_page;
83 #$self->{'isis_code_page'} = $code_page;
85 # create Text::Iconv object
86 my $cp = Text::Iconv->new($code_page,$self->{'code_page'});
88 $log->info("reading ISIS database '",$arg->{'filename'},"'");
89 $log->debug("isis code page: $code_page");
91 my ($isis_db,$maxmfn);
94 $log->debug("using OpenIsis perl bindings");
95 $isis_db = OpenIsis::open($arg->{'filename'});
96 $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1;
97 } elsif ($have_biblio_isis) {
98 $log->debug("using Biblio::Isis");
100 $isis_db = new Biblio::Isis(
101 isisdb => $arg->{'filename'},
102 include_deleted => 1,
104 my $l = shift || return;
105 $l = $cp->convert($l);
109 $maxmfn = $isis_db->count;
112 $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");
117 $log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN.");
123 if (my $s = $self->{'start_mfn'}) {
124 $log->info("skipping to MFN $s");
127 $self->{'start_mfn'} = $startmfn;
130 $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn});
132 $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));
136 for (my $mfn = $startmfn; $mfn <= $maxmfn; $mfn++) {
138 $log->debug("mfn: $mfn\n");
142 if ($have_openisis) {
144 # read record using OpenIsis
145 my $row = OpenIsis::read( $isis_db, $mfn );
146 foreach my $k (keys %{$row}) {
148 foreach my $l (@{$row->{$k}}) {
149 $l = $cp->convert($l);
153 foreach my $t (split(/\^/,$l)) {
155 $val->{substr($t,0,1)} = substr($t,1);
161 push @{$rec->{$k}}, $val;
164 push @{$rec->{'000'}}, $mfn;
168 } elsif ($have_biblio_isis) {
169 $rec = $isis_db->to_hash($mfn);
171 $log->logdie("hum? implementation missing?");
174 $log->confess("record $mfn empty?") unless ($rec);
177 if ($self->{'low_mem'}) {
178 $self->{'db'}->put($mfn, $rec);
180 $self->{'data'}->{$mfn} = $rec;
184 $self->{'lookup'}->add( $rec ) if ($self->{'lookup'} && can($self->{'lookup'}->add));
186 $self->progress_bar($mfn,$maxmfn);
190 $self->{'current_mfn'} = -1;
191 $self->{'last_pcnt'} = 0;
193 $log->debug("max mfn: $maxmfn");
195 # store max mfn and return it.
196 return $self->{'max_mfn'} = $maxmfn;
201 Fetch next record from database. It will also displays progress bar.
203 my $rec = $webpac->fetch_rec;
205 You should rearly have the need to call this function directly. Instead use
206 C<fetch_data_structure> which returns normalised data.
213 my $log = $self->_get_logger();
215 $log->logconfess("it seems that you didn't load database!") unless ($self->{'current_mfn'});
217 if ($self->{'current_mfn'} == -1) {
218 $self->{'current_mfn'} = $self->{'start_mfn'};
220 $self->{'current_mfn'}++;
223 my $mfn = $self->{'current_mfn'};
225 if ($mfn > $self->{'max_mfn'}) {
226 $self->{'current_mfn'} = $self->{'max_mfn'};
227 $log->debug("at EOF");
231 $self->progress_bar($mfn,$self->{'max_mfn'});
233 if ($self->{'low_mem'}) {
234 return $self->{'db'}->get($mfn);
236 return $self->{'data'}->{$mfn};
240 =head2 fetch_data_structure
242 Fetch data structure of next record from database.
244 my @ds = $webpac->fetch_data_structure;
248 sub fetch_data_structure {
251 return $self->data_structure(
258 Returns current record number (MFN).
266 return $self->{'current_mfn'};
271 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
273 =head1 COPYRIGHT & LICENSE
275 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
277 This program is free software; you can redistribute it and/or modify it
278 under the same terms as Perl itself.
282 1; # End of WebPAC::Input::ISIS