line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::VIAF::API::Extract; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2725
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
132
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has api_response => (is => 'ro', required => 1); |
10
|
|
|
|
|
|
|
has lang => (is => 'ro', default => 'nl-NL'); |
11
|
|
|
|
|
|
|
has fallback_lang => (is => 'ro', default => 'en-US'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub single { |
14
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
15
|
0
|
|
|
|
|
|
my $descriptions = $self->api_response->{'rdf:Description'}; |
16
|
0
|
|
|
|
|
|
my $person; |
17
|
0
|
|
|
|
|
|
foreach my $description (@{$descriptions}) { |
|
0
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
if ($self->is_person($description->{'rdf:type'}) == 1) { |
19
|
0
|
|
|
|
|
|
$person = $description; |
20
|
0
|
|
|
|
|
|
last; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
0
|
0
|
|
|
|
|
if (ref($person) ne "HASH") { |
24
|
0
|
|
|
|
|
|
return {}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
return { |
27
|
|
|
|
|
|
|
'skos:prefLabel' => $self->pref_label($person), |
28
|
|
|
|
|
|
|
'dcterms:identifier' => $person->{'dcterms:identifier'}->{'content'}, |
29
|
|
|
|
|
|
|
'schema:description' => $person->{'schema:description'}, |
30
|
|
|
|
|
|
|
'schema:birthDate' => $person->{'schema:birthDate'}, |
31
|
|
|
|
|
|
|
'schema:deathDate' => $person->{'schema:deathDate'}, |
32
|
0
|
|
|
|
|
|
'guid' => $person->{'rdf:about'} |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub pref_label { |
37
|
0
|
|
|
0
|
0
|
|
my ($self, $description) = @_; |
38
|
0
|
|
|
|
|
|
my $prefLabel; |
39
|
|
|
|
|
|
|
my $prefLabel_fallback; |
40
|
0
|
|
|
|
|
|
foreach my $label (@{$description->{'skos:prefLabel'}}) { |
|
0
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ($label->{'xml:lang'} eq $self->lang) { |
42
|
0
|
|
|
|
|
|
$prefLabel = $label->{'content'}; |
43
|
0
|
|
|
|
|
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
|
|
|
|
if ($label->{'xml:lang'} eq $self->fallback_lang) { |
46
|
0
|
|
|
|
|
|
$prefLabel_fallback = $label->{'content'}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if (!defined($prefLabel)) { |
51
|
|
|
|
|
|
|
# No guarantee that this isn't undefined |
52
|
0
|
|
|
|
|
|
return $prefLabel_fallback; |
53
|
|
|
|
|
|
|
} else { |
54
|
0
|
|
|
|
|
|
return $prefLabel; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub is_person { |
59
|
0
|
|
|
0
|
0
|
|
my ($self, $rdf_types) = @_; |
60
|
0
|
0
|
|
|
|
|
if (ref($rdf_types) ne 'ARRAY') { |
61
|
0
|
|
|
|
|
|
$rdf_types = [$rdf_types]; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
foreach my $rdf_type (@{$rdf_types}) { |
|
0
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ($rdf_type->{'rdf:resource'} eq 'http://schema.org/Person') { |
65
|
0
|
|
|
|
|
|
return 1; |
66
|
0
|
|
|
|
|
|
last; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |