| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::RIS; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
55183
|
use namespace::clean; |
|
|
1
|
|
|
|
|
13031
|
|
|
|
1
|
|
|
|
|
6
|
|
|
6
|
1
|
|
|
1
|
|
509
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
141445
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
1
|
|
|
1
|
|
252
|
use Catmandu::Util qw(:is :array); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
244
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has sep_char => (is => 'ro', default => sub {'\s+-?\s*'}); |
|
13
|
|
|
|
|
|
|
has human => (is => 'ro'); |
|
14
|
|
|
|
|
|
|
has ris => (is => 'lazy'); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_ris { |
|
17
|
2
|
|
|
2
|
|
15
|
my $self = shift; |
|
18
|
2
|
|
|
|
|
4
|
my $hash = {}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
100
|
66
|
|
|
70
|
if ($self->human && -r $self->human) { |
|
21
|
1
|
|
|
|
|
12
|
my $importer = Catmandu->importer('CSV', |
|
22
|
|
|
|
|
|
|
file => $self->human, |
|
23
|
|
|
|
|
|
|
header => 0 , |
|
24
|
|
|
|
|
|
|
fields => 'name,value' , |
|
25
|
|
|
|
|
|
|
sep_char => ',', |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
$importer->each(sub { |
|
28
|
1
|
|
|
1
|
|
728
|
my $item = shift; |
|
29
|
1
|
|
|
|
|
4
|
$hash->{$item->{name}} = $item->{value}; |
|
30
|
1
|
|
|
|
|
48693
|
}); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
1
|
|
|
|
|
8
|
while(<DATA>) { |
|
34
|
74
|
|
|
|
|
96
|
chomp; |
|
35
|
74
|
|
|
|
|
210
|
my ($n,$v) = split('\s*,\s*',$_,2); |
|
36
|
74
|
|
|
|
|
224
|
$hash->{$n} = $v; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} |
|
39
|
2
|
|
|
|
|
169
|
$hash; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub generator { |
|
43
|
|
|
|
|
|
|
my ($self) = @_; |
|
44
|
|
|
|
|
|
|
sub { |
|
45
|
|
|
|
|
|
|
state $fh = $self->fh; |
|
46
|
|
|
|
|
|
|
state $sep_char = $self->sep_char; |
|
47
|
|
|
|
|
|
|
state $pattern = qr/$sep_char/; |
|
48
|
|
|
|
|
|
|
state $line; |
|
49
|
|
|
|
|
|
|
state $data; |
|
50
|
|
|
|
|
|
|
my $previous_key= ''; |
|
51
|
|
|
|
|
|
|
while($line = <$fh>) { |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
chomp($line); |
|
54
|
|
|
|
|
|
|
next if $line eq ''; |
|
55
|
|
|
|
|
|
|
# Remove BOM |
|
56
|
|
|
|
|
|
|
$line =~ s/^\x{feff}//; |
|
57
|
|
|
|
|
|
|
$line =~ s/^\s\s/$previous_key/; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my ($key,$val) = split($pattern,$line,2); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
if ($key eq 'ER') { |
|
62
|
|
|
|
|
|
|
my $tmp = $data; |
|
63
|
|
|
|
|
|
|
$data = {}; |
|
64
|
|
|
|
|
|
|
return $tmp; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else { |
|
67
|
|
|
|
|
|
|
$key = $self->ris->{$key} if $self->human && exists $self->ris->{$key}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$previous_key = $key; |
|
70
|
|
|
|
|
|
|
$val =~ s/\r// if defined $val; |
|
71
|
|
|
|
|
|
|
# handle repeated fields |
|
72
|
|
|
|
|
|
|
if ($data->{$key}) { |
|
73
|
|
|
|
|
|
|
$data->{$key} = [ grep { is_string $_ } @{$data->{$key}} ] if is_array_ref $data->{$key}; |
|
74
|
|
|
|
|
|
|
$data->{$key} = [ $data->{$key} ] if is_string $data->{$key}; |
|
75
|
|
|
|
|
|
|
push @{$data->{$key}}, $val; |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
|
|
|
|
|
|
$data->{$key} = $val; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
return undef; |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Catmandu::Importer::RIS - a RIS importer |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Command line interface: |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
catmandu convert RIS < input.txt |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Use the --human option to translate RIS tags into human readable strings |
|
98
|
|
|
|
|
|
|
catmandu convert RIS --human 1 < input.txt |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Provide a comma separated mapping file to translate RIS tags |
|
101
|
|
|
|
|
|
|
catmandu convert RIS --human mappings/my_tags.txt < input.txt |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
In Perl code: |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Catmandu::Importer::RIS; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::RIS->new(file => "/foo/bar.txt"); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
|
110
|
|
|
|
|
|
|
my $hashref = $_[0]; |
|
111
|
|
|
|
|
|
|
# ... |
|
112
|
|
|
|
|
|
|
}); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item sep_char |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Set a field separator |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item human |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If set to 1, then RIS tries to translate tags into human readable strings. If set to |
|
125
|
|
|
|
|
|
|
a file name, then RIS will read the file as a comma delimited lists of tag/string |
|
126
|
|
|
|
|
|
|
translations. E.g. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
catmandu convert RIS --human mappings/my_tags.txt < input.txt |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
where mappings/my_tags.txt like: |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
A2,Secondary-Author |
|
133
|
|
|
|
|
|
|
A3,Tertiary-Author |
|
134
|
|
|
|
|
|
|
A4,Subsidiary-Author |
|
135
|
|
|
|
|
|
|
AB,Abstract |
|
136
|
|
|
|
|
|
|
AD,Author-Address |
|
137
|
|
|
|
|
|
|
AF,Notes |
|
138
|
|
|
|
|
|
|
. |
|
139
|
|
|
|
|
|
|
. |
|
140
|
|
|
|
|
|
|
. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=back |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 METHODS |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 new(file => $filename, fh => $fh , fix => [...]) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Create a new RIS importer for $filename. Use STDIN when no filename is given. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
The constructor inherits the fix parameter from L<Catmandu::Fixable>. When given, |
|
151
|
|
|
|
|
|
|
then any fix or fix script will be applied to imported items. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 count |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 each(&callback) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 ... |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Every L<Catmandu::Importer> is a L<Catmandu::Iterable> all its methods are |
|
160
|
|
|
|
|
|
|
inherited. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<Catmandu::Iterable> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__DATA__ |
|
169
|
|
|
|
|
|
|
TY,Type-of-Reference |
|
170
|
|
|
|
|
|
|
ER,End-of-Reference |
|
171
|
|
|
|
|
|
|
A2,Secondary-Author |
|
172
|
|
|
|
|
|
|
A3,Tertiary-Author |
|
173
|
|
|
|
|
|
|
A4,Subsidiary-Author |
|
174
|
|
|
|
|
|
|
AB,Abstract |
|
175
|
|
|
|
|
|
|
AD,Author-Address |
|
176
|
|
|
|
|
|
|
AF,Notes |
|
177
|
|
|
|
|
|
|
AN,Accession-Number |
|
178
|
|
|
|
|
|
|
AU,Author |
|
179
|
|
|
|
|
|
|
BP,Beginning-Page |
|
180
|
|
|
|
|
|
|
BS,Book-Series-Subtitle |
|
181
|
|
|
|
|
|
|
C1,Custom-1 |
|
182
|
|
|
|
|
|
|
C2,Custom-2 |
|
183
|
|
|
|
|
|
|
C3,Custom-3 |
|
184
|
|
|
|
|
|
|
C4,Custom-4 |
|
185
|
|
|
|
|
|
|
C5,Custom-5 |
|
186
|
|
|
|
|
|
|
C6,Custom-6 |
|
187
|
|
|
|
|
|
|
C7,Custom-7 |
|
188
|
|
|
|
|
|
|
C8,Custom-8 |
|
189
|
|
|
|
|
|
|
CA,Caption |
|
190
|
|
|
|
|
|
|
CP,Cited-Patent |
|
191
|
|
|
|
|
|
|
CR,Cited-References |
|
192
|
|
|
|
|
|
|
CY,Place-Published |
|
193
|
|
|
|
|
|
|
DA,Date |
|
194
|
|
|
|
|
|
|
DB,Name-of-Database |
|
195
|
|
|
|
|
|
|
DE,Author-Keywords |
|
196
|
|
|
|
|
|
|
DO,DOI |
|
197
|
|
|
|
|
|
|
DP,Database-Provide |
|
198
|
|
|
|
|
|
|
DT,Document-Type |
|
199
|
|
|
|
|
|
|
EM,Email-Address |
|
200
|
|
|
|
|
|
|
EP,Ending-Page |
|
201
|
|
|
|
|
|
|
ET,Edition |
|
202
|
|
|
|
|
|
|
FN,File-Type |
|
203
|
|
|
|
|
|
|
GA,ISI-Document-Delivery-Number |
|
204
|
|
|
|
|
|
|
IS,Issue |
|
205
|
|
|
|
|
|
|
J2,Alternate-Title |
|
206
|
|
|
|
|
|
|
J9,29-Character-Source-Title-Abreviation |
|
207
|
|
|
|
|
|
|
JI,ISO-Source-Title-Abbreviation |
|
208
|
|
|
|
|
|
|
KW,Keywords |
|
209
|
|
|
|
|
|
|
L1,File-Attachments |
|
210
|
|
|
|
|
|
|
L4,Figure |
|
211
|
|
|
|
|
|
|
LA,Language |
|
212
|
|
|
|
|
|
|
LB,Label |
|
213
|
|
|
|
|
|
|
ID,KeyWords-Plus |
|
214
|
|
|
|
|
|
|
IS,Number |
|
215
|
|
|
|
|
|
|
M3,Type-of-Work |
|
216
|
|
|
|
|
|
|
N1,Notes |
|
217
|
|
|
|
|
|
|
NR,Cited-Reference-Count |
|
218
|
|
|
|
|
|
|
NV,Number-of-Volumes |
|
219
|
|
|
|
|
|
|
OP,Original-Publication |
|
220
|
|
|
|
|
|
|
PA,Publisher-Address |
|
221
|
|
|
|
|
|
|
PB,Publisher |
|
222
|
|
|
|
|
|
|
PD,Publication-Date |
|
223
|
|
|
|
|
|
|
PG,Page-Count |
|
224
|
|
|
|
|
|
|
PI,Publisher-City |
|
225
|
|
|
|
|
|
|
PN,Part-Number |
|
226
|
|
|
|
|
|
|
PT,Publication-Type |
|
227
|
|
|
|
|
|
|
PU,Publisher |
|
228
|
|
|
|
|
|
|
PY,Year |
|
229
|
|
|
|
|
|
|
RP,Reprint-Address |
|
230
|
|
|
|
|
|
|
SC,Research-Area |
|
231
|
|
|
|
|
|
|
SE,Book-Series-Title |
|
232
|
|
|
|
|
|
|
SI,Special-Issue |
|
233
|
|
|
|
|
|
|
SN,ISSN |
|
234
|
|
|
|
|
|
|
SO,Full-Source-Title |
|
235
|
|
|
|
|
|
|
SU,Supplement |
|
236
|
|
|
|
|
|
|
TI,Title |
|
237
|
|
|
|
|
|
|
TC,Times-Cited |
|
238
|
|
|
|
|
|
|
UT,ISI-Unique-Article-Identifier |
|
239
|
|
|
|
|
|
|
VL,Volume |
|
240
|
|
|
|
|
|
|
VR,File-Format-Version-Number |
|
241
|
|
|
|
|
|
|
WC,Web-of-Science-Categories |
|
242
|
|
|
|
|
|
|
WP,Publisher-Web-Address |