line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::VIAF::API; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
9458
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
87
|
|
4
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
70
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
12
|
use Moo; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
24
|
|
7
|
4
|
|
|
4
|
|
776
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
23
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
2045
|
use Catmandu::VIAF::API::ID; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Catmandu::VIAF::API::Query; |
11
|
|
|
|
|
|
|
use Catmandu::VIAF::API::Extract; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has term => (is => 'ro', required => 1); |
14
|
|
|
|
|
|
|
has lang => (is => 'ro', default => 'nl-NL'); |
15
|
|
|
|
|
|
|
has fallback_lang => (is => 'ro', default => 'en-US'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub search { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
my $query = sprintf('local.mainHeadingEl = "%s" and local.personalNames = "%s"', $self->term, $self->term); |
20
|
|
|
|
|
|
|
my $api_q = Catmandu::VIAF::API::Query->new(query => $query, lang => $self->lang, fallback_lang => $self->fallback_lang); |
21
|
|
|
|
|
|
|
my $results = []; |
22
|
|
|
|
|
|
|
foreach my $result (@{$api_q->results}) { |
23
|
|
|
|
|
|
|
my $e = Catmandu::VIAF::API::Extract->new( |
24
|
|
|
|
|
|
|
api_response => $result, |
25
|
|
|
|
|
|
|
lang => $self->lang, |
26
|
|
|
|
|
|
|
fallback_lang => $self->fallback_lang |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
push @{$results}, $e->single(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
return $results; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub match { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $query = sprintf('local.mainHeadingEl exact "%s" and local.personalNames = "%s"', $self->term, $self->term); |
36
|
|
|
|
|
|
|
my $api_q = Catmandu::VIAF::API::Query->new(query => $query, lang => $self->lang, fallback_lang => $self->fallback_lang); |
37
|
|
|
|
|
|
|
if (scalar @{$api_q->results} >= 1) { |
38
|
|
|
|
|
|
|
my $result = shift @{$api_q->results}; |
39
|
|
|
|
|
|
|
my $e = Catmandu::VIAF::API::Extract->new( |
40
|
|
|
|
|
|
|
api_response => $result, |
41
|
|
|
|
|
|
|
lang => $self->lang, |
42
|
|
|
|
|
|
|
fallback_lang => $self->fallback_lang |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
return $e->single(); |
45
|
|
|
|
|
|
|
} else { |
46
|
|
|
|
|
|
|
return {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub id { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my $api_id = Catmandu::VIAF::API::ID->new(viafid => $self->term); |
53
|
|
|
|
|
|
|
my $e = Catmandu::VIAF::API::Extract->new( |
54
|
|
|
|
|
|
|
api_response => $api_id->result, |
55
|
|
|
|
|
|
|
lang => $self->lang, |
56
|
|
|
|
|
|
|
fallback_lang => $self->fallback_lang |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
return $e->single(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |