line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AAT::SPARQL; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
12
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
86
|
|
6
|
4
|
|
|
4
|
|
11
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
66
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
11
|
use Moo; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
14
|
|
9
|
4
|
|
|
4
|
|
705
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
16
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
2664
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
116916
|
|
|
4
|
|
|
|
|
124
|
|
12
|
4
|
|
|
4
|
|
548
|
use JSON; |
|
4
|
|
|
|
|
7781
|
|
|
4
|
|
|
|
|
24
|
|
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
|
|
966
|
my $self = shift; |
23
|
6
|
|
|
|
|
45
|
my $ua = LWP::UserAgent->new( |
24
|
|
|
|
|
|
|
agent => sprintf('catmandu-store-aat/%s', $VERSION) |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
# Otherwise, the endpoint blows up. |
27
|
6
|
|
|
|
|
6508
|
$ua->default_header('Accept' => '*/*'); |
28
|
6
|
|
|
|
|
229
|
return $ua; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_results { |
33
|
6
|
|
|
6
|
|
1054
|
my $self = shift; |
34
|
6
|
|
|
|
|
19
|
my $r = $self->get(); |
35
|
6
|
|
|
|
|
1223
|
return $r; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
6
|
|
|
6
|
0
|
6
|
my $self = shift; |
40
|
6
|
|
|
|
|
9
|
my $form_template = 'query=%s'; |
41
|
6
|
|
|
|
|
15
|
my $form = { |
42
|
|
|
|
|
|
|
'query' => $self->query |
43
|
|
|
|
|
|
|
}; |
44
|
6
|
|
|
|
|
54
|
my $response = $self->ua->post($self->url, $form); |
45
|
6
|
50
|
|
|
|
4236310
|
if ($response->is_success) { |
46
|
6
|
|
|
|
|
104
|
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 ?prefLabel ?id ?Subject ?scheme { |
72
|
|
|
|
|
|
|
?Subject xl:prefLabel|xl:altLabel [xl:literalForm ?prefLabel; dct:language gvp_lang:nl] . |
73
|
|
|
|
|
|
|
?Subject dc:identifier ?id . |
74
|
|
|
|
|
|
|
?Subject skos:inScheme <http://vocab.getty.edu/aat/> . |
75
|
|
|
|
|
|
|
?Subject skos:inScheme ?scheme . |
76
|
|
|
|
|
|
|
?Subject luc:term "schildering" . |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |