6 |
use WebPAC::Input; |
use WebPAC::Input; |
7 |
use base qw/WebPAC::Common/; |
use base qw/WebPAC::Common/; |
8 |
|
|
9 |
|
use Data::Dump qw/dump/; |
10 |
|
|
11 |
=head1 NAME |
=head1 NAME |
12 |
|
|
13 |
WebPAC::Input::ISI - support for ISI Export Format |
WebPAC::Input::ISI - support for ISI Export Format |
14 |
|
|
15 |
=head1 VERSION |
=head1 VERSION |
16 |
|
|
17 |
Version 0.00 |
Version 0.02 |
18 |
|
|
19 |
=cut |
=cut |
20 |
|
|
21 |
our $VERSION = '0.00'; |
our $VERSION = '0.02'; |
|
|
|
22 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
24 |
|
|
55 |
|
|
56 |
=cut |
=cut |
57 |
|
|
58 |
|
my $subfields = { |
59 |
|
'CR' => sub { |
60 |
|
my @v = split(/, /, shift); |
61 |
|
my $f; |
62 |
|
foreach ( qw/author year reference volume page/ ) { |
63 |
|
if ( my $tmp = shift @v ) { |
64 |
|
$f->{$_} = $tmp; |
65 |
|
} |
66 |
|
} |
67 |
|
if ( $f->{author} =~ /^\*(.+)/ ) { |
68 |
|
delete $f->{author}; |
69 |
|
$f->{institution} = $1; |
70 |
|
} |
71 |
|
return $f; |
72 |
|
}, |
73 |
|
}; |
74 |
|
|
75 |
sub new { |
sub new { |
76 |
my $class = shift; |
my $class = shift; |
77 |
my $self = {@_}; |
my $self = {@_}; |
103 |
|
|
104 |
$log->info("opening $format $version database '$arg->{path}'"); |
$log->info("opening $format $version database '$arg->{path}'"); |
105 |
|
|
106 |
|
my $tag; |
107 |
|
my $rec; |
108 |
|
|
109 |
|
while( $line = <$fh> ) { |
110 |
|
chomp($line); |
111 |
|
|
112 |
|
my $v; |
113 |
|
|
114 |
|
if ( $line =~ /^(\S\S)\s(.+)$/ ) { |
115 |
|
$tag = $1; |
116 |
|
$v = $2; |
117 |
|
} elsif ( $line =~ /^\s{3}(.+)$/ ) { |
118 |
|
$v = $1; |
119 |
|
} elsif ( $line eq 'ER' ) { |
120 |
|
# join tags |
121 |
|
foreach ( qw/AB DE ID TI/ ) { |
122 |
|
$rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_}; |
123 |
|
} |
124 |
|
push @{ $self->{_rec} }, $rec; |
125 |
|
$rec = {}; |
126 |
|
$line = <$fh>; |
127 |
|
chomp $line; |
128 |
|
$log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' ); |
129 |
|
} elsif ( $line eq 'EF' ) { |
130 |
|
last; |
131 |
|
} else { |
132 |
|
$log->logdie("can't parse +$. $arg->{path} : $line"); |
133 |
|
} |
134 |
|
|
135 |
|
if ( defined $v ) { |
136 |
|
$v = $subfields->{$tag}->($v) if defined $subfields->{$tag}; |
137 |
|
|
138 |
|
$log->debug("$tag: ", sub { dump( $v ) }); |
139 |
|
push @{ $rec->{$tag} }, $v; |
140 |
|
} |
141 |
|
|
142 |
|
} |
143 |
|
|
144 |
|
$log->debug("loaded ", $self->size, " records"); |
145 |
|
|
146 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
147 |
} |
} |
148 |
|
|
150 |
|
|
151 |
Return record with ID C<$mfn> from database |
Return record with ID C<$mfn> from database |
152 |
|
|
153 |
my $rec = $input->fetch_rec( $mfn, $filter_coderef); |
my $rec = $input->fetch_rec( $mfn, $filter_coderef ); |
154 |
|
|
155 |
=cut |
=cut |
156 |
|
|
157 |
sub fetch_rec { |
sub fetch_rec { |
158 |
my $self = shift; |
my $self = shift; |
159 |
|
|
160 |
my ($mfn, $filter_coderef) = @_; |
my ( $mfn, $filter_coderef ) = @_; |
161 |
|
|
162 |
my $rec; |
return $self->{_rec}->[$mfn-1]; |
|
|
|
|
return $rec; |
|
163 |
} |
} |
164 |
|
|
165 |
|
|
173 |
|
|
174 |
sub size { |
sub size { |
175 |
my $self = shift; |
my $self = shift; |
176 |
return 2; |
return $#{$self->{_rec}} + 1; |
177 |
} |
} |
178 |
|
|
179 |
|
=head1 SEE ALSO |
180 |
|
|
181 |
|
L<http://isibasic.com/help/helpprn.html> is only sane source of document format which Google could find... |
182 |
|
|
183 |
=head1 AUTHOR |
=head1 AUTHOR |
184 |
|
|
185 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |