| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::VIAF::API::Extract; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3195
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
121
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
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->name($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
|
|
|
|
|
|
my $prefLabel_nolang; |
|
41
|
0
|
0
|
|
|
|
|
if (ref($description->{'skos:prefLabel'}) ne 'ARRAY') { |
|
42
|
0
|
|
|
|
|
|
$description->{'skos:prefLabel'} = [$description->{'skos:prefLabel'}]; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
|
foreach my $label (@{$description->{'skos:prefLabel'}}) { |
|
|
0
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if (exists($label->{'xml:lang'})) { |
|
46
|
0
|
0
|
|
|
|
|
if ($label->{'xml:lang'} eq $self->lang) { |
|
47
|
0
|
|
|
|
|
|
$prefLabel = $label->{'content'}; |
|
48
|
0
|
|
|
|
|
|
last; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
0
|
|
|
|
|
if ($label->{'xml:lang'} eq $self->fallback_lang) { |
|
51
|
0
|
|
|
|
|
|
$prefLabel_fallback = $label->{'content'}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
0
|
|
|
|
|
|
$prefLabel_nolang = $label->{'content'}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if (defined($prefLabel)) { |
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $prefLabel; |
|
60
|
|
|
|
|
|
|
} elsif (defined($prefLabel_fallback)) { |
|
61
|
0
|
|
|
|
|
|
return $prefLabel_fallback; |
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
|
|
|
|
|
|
# No guarantee that this isn't undefined |
|
64
|
0
|
|
|
|
|
|
return $prefLabel_nolang; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub schema_name { |
|
69
|
0
|
|
|
0
|
0
|
|
my ($self, $description) = @_; |
|
70
|
0
|
|
|
|
|
|
my $name; |
|
71
|
|
|
|
|
|
|
my $name_fallback; |
|
72
|
0
|
|
|
|
|
|
my $name_nolang; |
|
73
|
0
|
0
|
|
|
|
|
if (ref($description->{'schema:name'}) ne 'ARRAY') { |
|
74
|
0
|
|
|
|
|
|
$description->{'schema:name'} = [$description->{'schema:name'}]; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
0
|
|
|
|
|
|
foreach my $s_name (@{$description->{'schema:name'}}) { |
|
|
0
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if (exists($s_name->{'xml:lang'})) { |
|
78
|
0
|
0
|
|
|
|
|
if ($s_name->{'xml:lang'} eq $self->lang) { |
|
79
|
0
|
|
|
|
|
|
$name = $s_name->{'content'}; |
|
80
|
0
|
|
|
|
|
|
last; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
0
|
|
|
|
|
if ($s_name->{'xml:lang'} eq $self->fallback_lang) { |
|
83
|
0
|
|
|
|
|
|
$name_fallback = $s_name->{'content'}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
0
|
|
|
|
|
|
$name_nolang = $s_name->{'content'}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
0
|
0
|
|
|
|
|
if (defined($name)) { |
|
|
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $name; |
|
91
|
|
|
|
|
|
|
} elsif (defined($name_fallback)) { |
|
92
|
0
|
|
|
|
|
|
return $name_fallback; |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
0
|
|
|
|
|
|
return $name_nolang; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub name { |
|
99
|
0
|
|
|
0
|
0
|
|
my ($self, $description) = @_; |
|
100
|
0
|
|
|
|
|
|
my $name = $self->pref_label($description); |
|
101
|
0
|
0
|
|
|
|
|
if (!defined($name)) { |
|
102
|
0
|
|
|
|
|
|
$name = $self->schema_name($description); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
|
return $name; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub is_person { |
|
108
|
0
|
|
|
0
|
0
|
|
my ($self, $rdf_types) = @_; |
|
109
|
0
|
0
|
|
|
|
|
if (ref($rdf_types) ne 'ARRAY') { |
|
110
|
0
|
|
|
|
|
|
$rdf_types = [$rdf_types]; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
0
|
|
|
|
|
|
foreach my $rdf_type (@{$rdf_types}) { |
|
|
0
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ($rdf_type->{'rdf:resource'} eq 'http://schema.org/Person') { |
|
114
|
0
|
|
|
|
|
|
return 1; |
|
115
|
0
|
|
|
|
|
|
last; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
0
|
|
|
|
|
|
return 0; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
|
122
|
|
|
|
|
|
|
__END__ |