7 |
BEGIN { |
BEGIN { |
8 |
use Exporter (); |
use Exporter (); |
9 |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
10 |
$VERSION = 0.04; |
$VERSION = 0.05; |
11 |
@ISA = qw (Exporter); |
@ISA = qw (Exporter); |
12 |
#Give a hoot don't pollute, do not export more than needed by default |
#Give a hoot don't pollute, do not export more than needed by default |
13 |
@EXPORT = qw (); |
@EXPORT = qw (); |
18 |
|
|
19 |
=head1 NAME |
=head1 NAME |
20 |
|
|
21 |
IsisDB - Read CDS/ISIS database |
IsisDB - Read CDS/ISIS, WinISIS and IsisMarc database |
22 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
24 |
|
|
34 |
|
|
35 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
36 |
|
|
37 |
This module will read CDS/ISIS databases and create hash values out of it. |
This module will read ISIS databases created by DOS CDS/ISIS, WinIsis or |
38 |
It can be used as perl-only alternative to OpenIsis module. |
IsisMarc. It can be used as perl-only alternative to OpenIsis module. |
39 |
|
|
40 |
This will module will always be slower that OpenIsis module which use C |
It can create hash values from data in ISIS database (using C<to_hash>), |
41 |
library. However, since it's written in perl, it's platform independent (so |
ASCII dump (using C<to_ascii>) or just hash with field names and packed |
42 |
you don't need C compiler), and can be easily modified. |
values (like C<^asomething^belse>). |
43 |
|
|
44 |
Unique feature of this module is ability to C<include_deleted> records. |
Unique feature of this module is ability to C<include_deleted> records. |
45 |
It will also skip zero sized fields (OpenIsis has a bug in XS bindings, so |
It will also skip zero sized fields (OpenIsis has a bug in XS bindings, so |
46 |
fields which are zero sized will be filled with random junk from memory). |
fields which are zero sized will be filled with random junk from memory). |
47 |
|
|
48 |
|
It also has support for identifiers (only if ISIS database is created by |
49 |
|
IsisMarc), see C<to_hash>. |
50 |
|
|
51 |
|
This will module will always be slower than OpenIsis module which use C |
52 |
|
library. However, since it's written in perl, it's platform independent (so |
53 |
|
you don't need C compiler), and can be easily modified. I hope that it |
54 |
|
creates data structures which are easier to use than ones created by |
55 |
|
OpenIsis, so reduced time in other parts of the code should compensate for |
56 |
|
slower performance of this module (speed of reading ISIS database is |
57 |
|
rarely an issue). |
58 |
|
|
59 |
=head1 METHODS |
=head1 METHODS |
60 |
|
|
61 |
=cut |
=cut |
76 |
|
|
77 |
=head2 new |
=head2 new |
78 |
|
|
79 |
Open CDS/ISIS database |
Open ISIS database |
80 |
|
|
81 |
my $isis = new IsisDB( |
my $isis = new IsisDB( |
82 |
isisdb => './cds/cds', |
isisdb => './cds/cds', |
95 |
|
|
96 |
=item isisdb |
=item isisdb |
97 |
|
|
98 |
Prefix path to CDS/ISIS. It should contain full or relative path to database |
This is full or relative path to ISIS database files which include |
99 |
and common prefix of C<.FDT>, C<.MST>, C<.CNT>, C<.XRF> and C<.MST> files. |
common prefix of C<.FDT>, C<.MST>, C<.CNT>, C<.XRF> and C<.MST> files. |
100 |
|
|
101 |
|
In this example it uses C<./cds/cds.MST> and related files. |
102 |
|
|
103 |
=item read_fdt |
=item read_fdt |
104 |
|
|
227 |
|
|
228 |
close(fileCNT); |
close(fileCNT); |
229 |
|
|
230 |
print Dumper($self) if ($self->{debug}); |
print Dumper($self),"\n" if ($self->{debug}); |
231 |
|
|
232 |
# open files for later |
# open files for later |
233 |
open($self->{'fileXRF'}, $self->{isisdb}.".XRF") || croak "can't open '$self->{isisdb}.XRF': $!"; |
open($self->{'fileXRF'}, $self->{isisdb}.".XRF") || croak "can't open '$self->{isisdb}.XRF': $!"; |
244 |
my $rec = $isis->fetch(55); |
my $rec = $isis->fetch(55); |
245 |
|
|
246 |
Returns hash with keys which are field names and values are unpacked values |
Returns hash with keys which are field names and values are unpacked values |
247 |
for that field (like C<^asometing^bsomething else>) |
for that field like this: |
248 |
|
|
249 |
|
$rec = { |
250 |
|
'210' => [ '^aNew York^cNew York University press^dcop. 1988' ], |
251 |
|
'990' => [ '2140', '88', 'HAY' ], |
252 |
|
}; |
253 |
|
|
254 |
=cut |
=cut |
255 |
|
|
373 |
} |
} |
374 |
close(fileMST); |
close(fileMST); |
375 |
|
|
376 |
print Dumper($self) if ($self->{debug}); |
print Dumper($self),"\n" if ($self->{debug}); |
377 |
|
|
378 |
return $self->{'record'}; |
return $self->{'record'}; |
379 |
} |
} |
380 |
|
|
381 |
=head2 to_ascii |
=head2 to_ascii |
382 |
|
|
383 |
Dump ascii output of selected MFN |
Dump ASCII output of record with specified MFN |
384 |
|
|
385 |
print $isis->to_ascii(55); |
print $isis->to_ascii(42); |
386 |
|
|
387 |
|
It outputs something like this: |
388 |
|
|
389 |
|
210 ^aNew York^cNew York University press^dcop. 1988 |
390 |
|
990 2140 |
391 |
|
990 88 |
392 |
|
990 HAY |
393 |
|
|
394 |
|
If C<read_fdt> is specified when calling C<new> it will display field names |
395 |
|
from C<.FDT> file instead of numeric tags. |
396 |
|
|
397 |
=cut |
=cut |
398 |
|
|
406 |
my $out = "0\t$mfn"; |
my $out = "0\t$mfn"; |
407 |
|
|
408 |
foreach my $f (sort keys %{$rec}) { |
foreach my $f (sort keys %{$rec}) { |
409 |
$out .= "\n$f\t".join("\n$f\t",@{$self->{record}->{$f}}); |
my $fn = $self->tag_name($f); |
410 |
|
$out .= "\n$fn\t".join("\n$fn\t",@{$self->{record}->{$f}}); |
411 |
} |
} |
412 |
|
|
413 |
$out .= "\n"; |
$out .= "\n"; |
417 |
|
|
418 |
=head2 to_hash |
=head2 to_hash |
419 |
|
|
420 |
Read mfn and convert it to hash |
Read record with specified MFN and convert it to hash |
421 |
|
|
422 |
my $hash = $isis->to_hash($mfn); |
my $hash = $isis->to_hash($mfn); |
423 |
|
|
424 |
It has ability to convert characters (using C<hash_filter> from ISIS |
It has ability to convert characters (using C<hash_filter> from ISIS |
425 |
database before creating structures enabling character remapping or quick |
database before creating structures enabling character re-mapping or quick |
426 |
fixup of data. |
fix-up of data. |
427 |
|
|
428 |
This function returns hash which is like this: |
This function returns hash which is like this: |
429 |
|
|
442 |
], |
], |
443 |
}; |
}; |
444 |
|
|
445 |
You can later use that has to produce any output from ISIS data. |
You can later use that hash to produce any output from ISIS data. |
446 |
|
|
447 |
|
If database is created using IsisMarc, it will also have to special fields |
448 |
|
which will be used for identifiers, C<i1> and C<i2> like this: |
449 |
|
|
450 |
|
'200' => [ |
451 |
|
{ |
452 |
|
'i1' => '1', |
453 |
|
'i2' => ' ' |
454 |
|
'a' => 'Goa', |
455 |
|
'f' => 'Valdo D\'Arienzo', |
456 |
|
'e' => 'tipografie e tipografi nel XVI secolo', |
457 |
|
} |
458 |
|
], |
459 |
|
|
460 |
|
This method will also create additional field C<000> with MFN. |
461 |
|
|
462 |
=cut |
=cut |
463 |
|
|
466 |
|
|
467 |
my $mfn = shift || confess "need mfn!"; |
my $mfn = shift || confess "need mfn!"; |
468 |
|
|
469 |
my $rec; |
# init record to include MFN as field 000 |
470 |
|
my $rec = { '000' => $mfn }; |
471 |
|
|
472 |
my $row = $self->fetch($mfn); |
my $row = $self->fetch($mfn); |
473 |
|
|
474 |
foreach my $k (keys %{$row}) { |
foreach my $k (keys %{$row}) { |
477 |
# filter output |
# filter output |
478 |
$l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'}); |
$l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'}); |
479 |
|
|
|
# has subfields? |
|
480 |
my $val; |
my $val; |
481 |
|
|
482 |
|
# has identifiers? |
483 |
|
($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])//); |
484 |
|
|
485 |
|
# has subfields? |
486 |
if ($l =~ m/\^/) { |
if ($l =~ m/\^/) { |
487 |
foreach my $t (split(/\^/,$l)) { |
foreach my $t (split(/\^/,$l)) { |
488 |
next if (! $t); |
next if (! $t); |
499 |
return $rec; |
return $rec; |
500 |
} |
} |
501 |
|
|
502 |
# |
=head2 tag_name |
|
# XXX porting from php left-over: |
|
|
# |
|
|
# do I *REALLY* need those methods, or should I use |
|
|
# $self->{something} directly? |
|
|
# |
|
|
# Probably direct usage is better! |
|
|
# |
|
503 |
|
|
504 |
sub TagName { |
Return name of selected tag |
505 |
my $self = shift; |
|
506 |
return $self->{TagName}; |
print $isis->tag_name('200'); |
|
} |
|
507 |
|
|
508 |
sub NextMFN { |
=cut |
509 |
|
|
510 |
|
sub tag_name { |
511 |
my $self = shift; |
my $self = shift; |
512 |
return $self->{NXTMFN}; |
my $tag = shift || return; |
513 |
|
return $self->{'TagName'}->{$tag} || $tag; |
514 |
} |
} |
515 |
|
|
516 |
1; |
1; |
526 |
dpavlin@rot13.org |
dpavlin@rot13.org |
527 |
http://www.rot13.org/~dpavlin/ |
http://www.rot13.org/~dpavlin/ |
528 |
|
|
529 |
This module is based heavily on code from LIBISIS.PHP - Library to read ISIS files V0.1.1 |
This module is based heavily on code from C<LIBISIS.PHP> library to read ISIS files V0.1.1 |
530 |
written in php and (c) 2000 Franck Martin - <franck@sopac.org> released under LGPL. |
written in php and (c) 2000 Franck Martin <franck@sopac.org> and released under LGPL. |
531 |
|
|
532 |
=head1 COPYRIGHT |
=head1 COPYRIGHT |
533 |
|
|
540 |
|
|
541 |
=head1 SEE ALSO |
=head1 SEE ALSO |
542 |
|
|
543 |
L<http://www.openisis.org|OpenIsis>, perl(1). |
OpenIsis web site L<http://www.openisis.org> |
544 |
|
|
545 |
|
perl4lib site L<http://perl4lib.perl.org> |
546 |
|
|