line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AAT::SPARQL; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
14
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
101
|
|
6
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
69
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
10
|
use Moo; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
13
|
|
9
|
4
|
|
|
4
|
|
710
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
18
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
2541
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
115561
|
|
|
4
|
|
|
|
|
116
|
|
12
|
4
|
|
|
4
|
|
541
|
use JSON; |
|
4
|
|
|
|
|
7333
|
|
|
4
|
|
|
|
|
26
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has query => (is => 'ro', required => 1); |
15
|
|
|
|
|
|
|
has url => (is => 'ro', default => 'http://vocab.getty.edu/sparql.json'); |
16
|
|
|
|
|
|
|
has lang => (is => 'ro', default => 'nl'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has results => (is => 'lazy'); |
19
|
|
|
|
|
|
|
has ua => (is => 'lazy'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _build_ua { |
22
|
6
|
|
|
6
|
|
1093
|
my $self = shift; |
23
|
6
|
|
|
|
|
51
|
my $ua = LWP::UserAgent->new( |
24
|
|
|
|
|
|
|
agent => sprintf('catmandu-store-aat/%s', $VERSION) |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
# Otherwise, the endpoint blows up. |
27
|
6
|
|
|
|
|
7552
|
$ua->default_header('Accept' => '*/*'); |
28
|
6
|
|
|
|
|
252
|
return $ua; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_results { |
33
|
6
|
|
|
6
|
|
1081
|
my $self = shift; |
34
|
6
|
|
|
|
|
16
|
my $r = $self->get(); |
35
|
6
|
|
|
|
|
1039
|
return $r; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
40
|
6
|
|
|
|
|
10
|
my $form_template = 'query=%s'; |
41
|
6
|
|
|
|
|
18
|
my $form = { |
42
|
|
|
|
|
|
|
'query' => $self->query |
43
|
|
|
|
|
|
|
}; |
44
|
6
|
|
|
|
|
51
|
my $response = $self->ua->post($self->url, $form); |
45
|
6
|
50
|
|
|
|
123678592
|
if ($response->is_success) { |
46
|
6
|
|
|
|
|
114
|
return decode_json($response->decoded_content); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
Catmandu::HTTPError->throw({ |
49
|
|
|
|
|
|
|
code => $response->code, |
50
|
|
|
|
|
|
|
message => $response->status_line, |
51
|
|
|
|
|
|
|
url => $response->request->uri, |
52
|
|
|
|
|
|
|
method => $response->request->method, |
53
|
|
|
|
|
|
|
request_headers => [], |
54
|
|
|
|
|
|
|
request_body => $response->request->decoded_content, |
55
|
|
|
|
|
|
|
response_headers => [], |
56
|
|
|
|
|
|
|
response_body => $response->decoded_content |
57
|
|
|
|
|
|
|
}); |
58
|
0
|
|
|
|
|
|
return undef; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 SPARQL Query |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
select ?anyLabel ?id ?Subject ?scheme { |
72
|
|
|
|
|
|
|
?Subject xl:prefLabel|xl:altLabel [xl:literalForm ?anyLabel; dct:language gvp_lang:nl] . |
73
|
|
|
|
|
|
|
values ?scheme {<http://vocab.getty.edu/aat/>} . |
74
|
|
|
|
|
|
|
?Subject dc:identifier ?id . |
75
|
|
|
|
|
|
|
?Subject skos:inScheme ?scheme . |
76
|
|
|
|
|
|
|
?Subject luc:term "schildering" . |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |