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