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 |
|
|
|
=head1 VERSION |
|
|
|
|
|
Version 0.00 |
|
|
|
|
15 |
=cut |
=cut |
16 |
|
|
17 |
our $VERSION = '0.00'; |
our $VERSION = '0.03'; |
|
|
|
18 |
|
|
19 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
20 |
|
|
51 |
|
|
52 |
=cut |
=cut |
53 |
|
|
54 |
|
my $subfields = { |
55 |
|
'CR' => sub { |
56 |
|
my $full_cr = shift; |
57 |
|
my @v = split(/, /, $full_cr); |
58 |
|
my $f = { full => $full_cr }; |
59 |
|
foreach ( qw/author year reference volume page doi/ ) { |
60 |
|
if ( my $tmp = shift @v ) { |
61 |
|
$f->{$_} = $tmp; |
62 |
|
} |
63 |
|
} |
64 |
|
if ( $f->{author} =~ /^\*(.+)/ ) { |
65 |
|
delete $f->{author}; |
66 |
|
$f->{institution} = $1; |
67 |
|
} |
68 |
|
$f->{doi} =~ s{DOI\s+}{} if $f->{doi}; # strip DOI prefix |
69 |
|
return $f; |
70 |
|
}, |
71 |
|
}; |
72 |
|
|
73 |
sub new { |
sub new { |
74 |
my $class = shift; |
my $class = shift; |
75 |
my $self = {@_}; |
my $self = {@_}; |
101 |
|
|
102 |
$log->info("opening $format $version database '$arg->{path}'"); |
$log->info("opening $format $version database '$arg->{path}'"); |
103 |
|
|
104 |
|
my $tag; |
105 |
|
my $rec; |
106 |
|
|
107 |
|
$self->{size} = 0; |
108 |
|
my $max_size; |
109 |
|
$max_size = ( $self->{offset} || 0 ) + $self->{limit} if $self->{limit}; |
110 |
|
|
111 |
|
warn "# max_size: $max_size"; |
112 |
|
|
113 |
|
while( $line = <$fh> ) { |
114 |
|
chomp($line); |
115 |
|
|
116 |
|
my $v; |
117 |
|
|
118 |
|
if ( $line =~ /^(\S\S)\s(.+)$/ ) { |
119 |
|
$tag = $1; |
120 |
|
$v = $2; |
121 |
|
} elsif ( $line =~ /^\s{3}(.+)$/ ) { |
122 |
|
$v = $1; |
123 |
|
if ( $tag eq 'CR' && $v =~ m{DOI$} ) { |
124 |
|
my $doi = <$fh>; |
125 |
|
chomp($doi); |
126 |
|
$doi =~ s{^\s{3}}{ } || die "can't find DOI in: $doi"; |
127 |
|
$v .= $doi; |
128 |
|
} |
129 |
|
} elsif ( $line eq 'ER' ) { |
130 |
|
# join tags |
131 |
|
foreach ( qw/AB DE ID TI SO RP SC FU FX/ ) { |
132 |
|
$rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_}; |
133 |
|
} |
134 |
|
# split on ; |
135 |
|
foreach ( qw/ID SC DE/ ) { |
136 |
|
$rec->{$_} = [ split(/;\s/, $rec->{$_}) ] if defined $rec->{$_}; |
137 |
|
} |
138 |
|
$rec->{'000'} = [ ++$self->{size} ]; |
139 |
|
push @{ $self->{_rec} }, $rec; |
140 |
|
|
141 |
|
last if $max_size && $self->{size} == $max_size; |
142 |
|
|
143 |
|
$rec = {}; |
144 |
|
$line = <$fh>; |
145 |
|
chomp $line; |
146 |
|
$log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' ); |
147 |
|
} elsif ( $line eq 'EF' ) { |
148 |
|
last; |
149 |
|
} else { |
150 |
|
$log->logdie("can't parse +$. $arg->{path} : $line"); |
151 |
|
} |
152 |
|
|
153 |
|
if ( defined $v ) { |
154 |
|
$v = $subfields->{$tag}->($v) if defined $subfields->{$tag}; |
155 |
|
|
156 |
|
$log->debug("$tag: ", sub { dump( $v ) }); |
157 |
|
push @{ $rec->{$tag} }, $v; |
158 |
|
} |
159 |
|
|
160 |
|
} |
161 |
|
|
162 |
|
$log->debug("loaded ", $self->size, " records"); |
163 |
|
|
164 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
165 |
} |
} |
166 |
|
|
168 |
|
|
169 |
Return record with ID C<$mfn> from database |
Return record with ID C<$mfn> from database |
170 |
|
|
171 |
my $rec = $input->fetch_rec( $mfn, $filter_coderef); |
my $rec = $input->fetch_rec( $mfn, $filter_coderef ); |
172 |
|
|
173 |
=cut |
=cut |
174 |
|
|
175 |
sub fetch_rec { |
sub fetch_rec { |
176 |
my $self = shift; |
my $self = shift; |
177 |
|
|
178 |
my ($mfn, $filter_coderef) = @_; |
my ( $mfn, $filter_coderef ) = @_; |
179 |
|
|
180 |
my $rec; |
return $self->{_rec}->[$mfn-1]; |
|
|
|
|
return $rec; |
|
181 |
} |
} |
182 |
|
|
183 |
|
|
191 |
|
|
192 |
sub size { |
sub size { |
193 |
my $self = shift; |
my $self = shift; |
194 |
return 2; |
return $self->{size}; |
195 |
} |
} |
196 |
|
|
197 |
|
=head1 SEE ALSO |
198 |
|
|
199 |
|
L<http://isibasic.com/help/helpprn.html> is only sane source of document format which Google could find... |
200 |
|
|
201 |
=head1 AUTHOR |
=head1 AUTHOR |
202 |
|
|
203 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |