| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::WoS; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
456
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
482
|
use MIME::Base64 qw(encode_base64); |
|
|
1
|
|
|
|
|
539
|
|
|
|
1
|
|
|
|
|
68
|
|
|
8
|
1
|
|
|
1
|
|
283
|
use XML::Compile::WSDL11; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XML::Compile::SOAP11; |
|
10
|
|
|
|
|
|
|
use XML::Compile::Transport::SOAPHTTP; |
|
11
|
|
|
|
|
|
|
use XML::LibXML::Simple qw(XMLin); |
|
12
|
|
|
|
|
|
|
use Catmandu::WoS::WSDL; |
|
13
|
|
|
|
|
|
|
use Catmandu::WoS::AuthWSDL; |
|
14
|
|
|
|
|
|
|
use Moo; |
|
15
|
|
|
|
|
|
|
use namespace::clean; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has username => (is => 'ro', required => 1); |
|
20
|
|
|
|
|
|
|
has password => (is => 'ro', required => 1); |
|
21
|
|
|
|
|
|
|
has query => (is => 'ro'); |
|
22
|
|
|
|
|
|
|
has cited_references => (is => 'ro'); |
|
23
|
|
|
|
|
|
|
has session_id => (is => 'lazy'); |
|
24
|
|
|
|
|
|
|
has _init => (is => 'lazy'); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# clients |
|
27
|
|
|
|
|
|
|
has _search => (is => 'rwp'); |
|
28
|
|
|
|
|
|
|
has _retrieve => (is => 'rwp'); |
|
29
|
|
|
|
|
|
|
has _citedReferences => (is => 'rwp'); |
|
30
|
|
|
|
|
|
|
has _citedReferencesRetrieve => (is => 'rwp'); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_session_id { |
|
33
|
|
|
|
|
|
|
my ($self) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $wsdl = XML::Compile::WSDL11->new(Catmandu::WoS::AuthWSDL->xml); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $authenticate = $wsdl->compileClient( |
|
38
|
|
|
|
|
|
|
'authenticate', |
|
39
|
|
|
|
|
|
|
transport_hook => sub { |
|
40
|
|
|
|
|
|
|
my ($req, $trace) = @_; |
|
41
|
|
|
|
|
|
|
my $auth = 'Basic ' |
|
42
|
|
|
|
|
|
|
. encode_base64(join(':', $self->username, $self->password)); |
|
43
|
|
|
|
|
|
|
$req->header(Authorization => $auth); |
|
44
|
|
|
|
|
|
|
my $ua = $trace->{user_agent}; |
|
45
|
|
|
|
|
|
|
$ua->request($req); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
undef $wsdl; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $res = $authenticate->(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ($res->{Fault}) { |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# TODO |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$res->{parameters}{return}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _build__init { |
|
62
|
|
|
|
|
|
|
my ($self) = @_; |
|
63
|
|
|
|
|
|
|
my $session_id = $self->session_id; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $wsdl = XML::Compile::WSDL11->new(Catmandu::WoS::WSDL->xml); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $transport_hook = sub { |
|
68
|
|
|
|
|
|
|
my ($req, $trace) = @_; |
|
69
|
|
|
|
|
|
|
$req->header(Cookie => qq|SID="$session_id"|); |
|
70
|
|
|
|
|
|
|
my $ua = $trace->{user_agent}; |
|
71
|
|
|
|
|
|
|
$ua->request($req); |
|
72
|
|
|
|
|
|
|
}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
if ($self->query) { |
|
75
|
|
|
|
|
|
|
$self->_set__search( |
|
76
|
|
|
|
|
|
|
$wsdl->compileClient('search', transport_hook => $transport_hook) |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
$self->_set__retrieve( |
|
79
|
|
|
|
|
|
|
$wsdl->compileClient( |
|
80
|
|
|
|
|
|
|
'retrieve', transport_hook => $transport_hook |
|
81
|
|
|
|
|
|
|
) |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
elsif ($self->cited_references) { |
|
85
|
|
|
|
|
|
|
$self->_set__citedReferences( |
|
86
|
|
|
|
|
|
|
$wsdl->compileClient( |
|
87
|
|
|
|
|
|
|
'citedReferences', transport_hook => $transport_hook |
|
88
|
|
|
|
|
|
|
) |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
$self->_set__citedReferencesRetrieve( |
|
91
|
|
|
|
|
|
|
$wsdl->compileClient( |
|
92
|
|
|
|
|
|
|
'citedReferencesRetrieve', transport_hook => $transport_hook |
|
93
|
|
|
|
|
|
|
) |
|
94
|
|
|
|
|
|
|
); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
undef $wsdl; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub generator { |
|
103
|
|
|
|
|
|
|
my ($self) = @_; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->_init; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub { |
|
108
|
|
|
|
|
|
|
state $recs = []; |
|
109
|
|
|
|
|
|
|
state $query_id; |
|
110
|
|
|
|
|
|
|
state $start = 1; |
|
111
|
|
|
|
|
|
|
state $limit = 100; |
|
112
|
|
|
|
|
|
|
state $total; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if (!@$recs) { |
|
115
|
|
|
|
|
|
|
return if defined $total && $start > $total; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $res; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if (defined $query_id) { |
|
120
|
|
|
|
|
|
|
my $args = { |
|
121
|
|
|
|
|
|
|
queryId => $query_id, |
|
122
|
|
|
|
|
|
|
retrieveParameters => |
|
123
|
|
|
|
|
|
|
{firstRecord => $start, count => $limit,} |
|
124
|
|
|
|
|
|
|
}; |
|
125
|
|
|
|
|
|
|
if ($self->query) { |
|
126
|
|
|
|
|
|
|
$res = $self->_retrieve->(%$args); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
elsif ($self->cited_references) { |
|
129
|
|
|
|
|
|
|
$res = $self->_citedReferencesRetrieve->(%$args); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$query_id = $res->{parameters}{return}{queryId} |
|
133
|
|
|
|
|
|
|
if !$res->{Fault}; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
else { |
|
136
|
|
|
|
|
|
|
my $args = { |
|
137
|
|
|
|
|
|
|
retrieveParameters => |
|
138
|
|
|
|
|
|
|
{firstRecord => $start, count => $limit,}, |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
}; |
|
141
|
|
|
|
|
|
|
if ($self->query) { |
|
142
|
|
|
|
|
|
|
$res = $self->_search->( |
|
143
|
|
|
|
|
|
|
%$args, |
|
144
|
|
|
|
|
|
|
queryParameters => { |
|
145
|
|
|
|
|
|
|
databaseId => 'WOS', |
|
146
|
|
|
|
|
|
|
queryLanguage => 'en', |
|
147
|
|
|
|
|
|
|
userQuery => $self->query, |
|
148
|
|
|
|
|
|
|
}, |
|
149
|
|
|
|
|
|
|
); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
elsif ($self->cited_references) { |
|
152
|
|
|
|
|
|
|
$res = $self->_citedReferences->( |
|
153
|
|
|
|
|
|
|
%$args, |
|
154
|
|
|
|
|
|
|
databaseId => 'WOS', |
|
155
|
|
|
|
|
|
|
queryLanguage => 'en', |
|
156
|
|
|
|
|
|
|
uid => $self->cited_references, |
|
157
|
|
|
|
|
|
|
); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
if ($res->{Fault}) { |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# TODO |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$total //= $res->{parameters}{return}{recordsFound}; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
return unless $total; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$start += $limit; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
if ($self->query) { |
|
173
|
|
|
|
|
|
|
my $xml = XMLin($res->{parameters}{return}{records}, |
|
174
|
|
|
|
|
|
|
ForceArray => 1); |
|
175
|
|
|
|
|
|
|
$recs = $xml->{REC}; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
elsif ($self->cited_references) { |
|
178
|
|
|
|
|
|
|
$recs = $res->{parameters}{return}{references}; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
shift @$recs; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
__END__ |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=encoding utf-8 |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 NAME |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Catmandu::Importer::WoS - Import Web of Science records |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# On the command line |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$ catmandu convert WoS --username XXX -password XXX --query 'TS=(lead OR cadmium)' to YAML |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# In perl |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
use Catmandu::Importer::WoS; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
my $wos = Catmandu::Importer::WoS->new(username => 'XXX', password => 'XXX', query => 'TS=(lead OR cadmium)'); |
|
207
|
|
|
|
|
|
|
$wos->each(sub { |
|
208
|
|
|
|
|
|
|
my $record = shift; |
|
209
|
|
|
|
|
|
|
# ... |
|
210
|
|
|
|
|
|
|
}); |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
my $wos = Catmandu::Importer::WoS->new(username => 'XXX', password => 'XXX', cited_references => '000393351200025'); |
|
213
|
|
|
|
|
|
|
$wos->each(sub { |
|
214
|
|
|
|
|
|
|
my $cite = shift; |
|
215
|
|
|
|
|
|
|
# ... |
|
216
|
|
|
|
|
|
|
}); |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 AUTHOR |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Nicolas Steenlant E<lt>nicolas.steenlant@ugent.beE<gt> |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Copyright 2017- Nicolas Steenlant |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 LICENSE |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
229
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |