line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::AAT::API; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
9214
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
87
|
|
4
|
4
|
|
|
4
|
|
9
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
11
|
use Moo; |
|
4
|
|
|
|
|
2
|
|
|
4
|
|
|
|
|
19
|
|
7
|
4
|
|
|
4
|
|
799
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
24
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
1921
|
use Catmandu::Store::AAT::SPARQL; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1756
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has term => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
has language => (is => 'ro', default => 'nl'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
## |
15
|
|
|
|
|
|
|
# Search for a term |
16
|
|
|
|
|
|
|
sub search { |
17
|
2
|
|
|
2
|
0
|
2532
|
my $self = shift; |
18
|
2
|
|
|
|
|
4
|
my $search_query = '?Subject luc:term "%s" .'; |
19
|
2
|
|
|
|
|
17
|
my $query = $self->build_query(sprintf($search_query, $self->term)); |
20
|
2
|
|
|
|
|
5
|
return $self->request($query); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
## |
24
|
|
|
|
|
|
|
# Exactly match a term |
25
|
|
|
|
|
|
|
sub match { |
26
|
2
|
|
|
2
|
0
|
2078
|
my $self = shift; |
27
|
2
|
|
|
|
|
3
|
my $match_query = '?Subject skos:prefLabel "%s"@%s .'; |
28
|
2
|
|
|
|
|
17
|
my $query = $self->build_query(sprintf($match_query, $self->term, $self->language)); |
29
|
2
|
|
|
|
|
4
|
my $result = $self->request($query); |
30
|
2
|
50
|
|
|
|
9
|
if (scalar @{$result} >= 1) { |
|
2
|
|
|
|
|
6
|
|
31
|
2
|
|
|
|
|
73
|
return $result->[0]; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
0
|
return {}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## |
38
|
|
|
|
|
|
|
# By ID |
39
|
|
|
|
|
|
|
sub id { |
40
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
41
|
2
|
|
|
|
|
4
|
my $id_query = '?Subject dc:identifier "%s" .'; |
42
|
2
|
|
|
|
|
20
|
my $query = $self->build_query(sprintf($id_query, $self->term)); |
43
|
2
|
|
|
|
|
9
|
my $result = $self->request($query); |
44
|
2
|
50
|
|
|
|
11
|
if (scalar @{$result} >= 1) { |
|
2
|
|
|
|
|
8
|
|
45
|
2
|
|
|
|
|
70
|
return $result->[0]; |
46
|
|
|
|
|
|
|
} else { |
47
|
0
|
|
|
|
|
0
|
return {}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub request { |
52
|
6
|
|
|
6
|
0
|
10
|
my ($self, $query) = @_; |
53
|
6
|
|
|
|
|
81
|
my $sparql = Catmandu::Store::AAT::SPARQL->new(query => $query, lang => $self->language); |
54
|
6
|
50
|
|
|
|
2717
|
if (defined ($sparql->results)) { |
55
|
6
|
|
|
|
|
262
|
return $self->parse($sparql->results); |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
return []; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub parse { |
63
|
6
|
|
|
6
|
0
|
63
|
my ($self, $raw_results) = @_; |
64
|
6
|
|
|
|
|
13
|
my $results = []; |
65
|
|
|
|
|
|
|
|
66
|
6
|
|
|
|
|
12
|
foreach my $raw_result (@{$raw_results->{'results'}->{'bindings'}}) { |
|
6
|
|
|
|
|
25
|
|
67
|
|
|
|
|
|
|
my $result = { |
68
|
|
|
|
|
|
|
'prefLabel' => $raw_result->{'prefLabel'}->{'value'}, |
69
|
|
|
|
|
|
|
'id' => $raw_result->{'id'}->{'value'}, |
70
|
65
|
|
|
|
|
111
|
'uri' => $raw_result->{'Subject'}->{'value'} |
71
|
|
|
|
|
|
|
}; |
72
|
65
|
|
|
|
|
44
|
push @{$results}, $result; |
|
65
|
|
|
|
|
76
|
|
73
|
|
|
|
|
|
|
} |
74
|
6
|
|
|
|
|
239
|
return $results; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub build_query { |
78
|
6
|
|
|
6
|
0
|
14
|
my ($self, $match_query) = @_; |
79
|
6
|
|
|
|
|
9
|
my $query = q(select ?prefLabel ?id ?Subject ?scheme { ?Subject xl:prefLabel [xl:literalForm ?prefLabel; dct:language gvp_lang:%s] . ?Subject dc:identifier ?id . ?Subject skos:inScheme <http://vocab.getty.edu/aat/> . ?Subject skos:inScheme ?scheme . %s }); |
80
|
6
|
|
|
|
|
35
|
return sprintf($query, $self->language, $match_query); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1. |
84
|
|
|
|
|
|
|
__END__ |