line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::wd_simple_claims; |
2
|
|
|
|
|
|
|
#ABSTRACT: Simplify claims of a Wikidata entity record |
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; #VERSION |
4
|
1
|
|
|
1
|
|
1341
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
228
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# TODO: also support other snak types |
8
|
|
|
|
|
|
|
# See https://www.mediawiki.org/wiki/Wikibase/DataModel for more |
9
|
|
|
|
|
|
|
sub simplify_snak { |
10
|
0
|
|
|
0
|
0
|
|
my ($snak) = @_; |
11
|
0
|
|
|
|
|
|
delete $snak->{property}; # redundant |
12
|
0
|
0
|
|
|
|
|
if ($snak->{datavalue}) { # innecessary nesting |
13
|
0
|
|
|
|
|
|
for (keys %{$snak->{datavalue}}) { |
|
0
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
$snak->{$_} = $snak->{datavalue}->{$_}; |
15
|
|
|
|
|
|
|
} |
16
|
0
|
0
|
|
|
|
|
if ($snak->{datatype} eq 'wikibase-item') { |
17
|
0
|
|
|
|
|
|
$snak->{value} = $snak->{value}->{'numeric-id'};; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
delete $snak->{type}; # equals to datatype |
20
|
0
|
|
|
|
|
|
delete $snak->{datavalue}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub fix { |
25
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
my $claims = $data->{claims} or return $data; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
while (my ($property,$cs) = each %$claims) { |
30
|
0
|
|
|
|
|
|
for my $c (@$cs) { |
31
|
0
|
|
|
|
|
|
delete $c->{id}; # internal |
32
|
0
|
|
|
|
|
|
delete $c->{type}; # always "statement" |
33
|
0
|
|
|
|
|
|
simplify_snak($c->{mainsnak}); |
34
|
0
|
|
|
|
|
|
for (keys %{$c->{mainsnak}}) { # innecessary nesting |
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$c->{$_} = $c->{mainsnak}->{$_}; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
delete $c->{mainsnak}; |
38
|
0
|
0
|
|
|
|
|
if ($c->{references}) { |
39
|
0
|
|
|
|
|
|
for my $r (@{$c->{references}}) { |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
delete $r->{hash}; # internal |
41
|
0
|
0
|
|
|
|
|
next unless $r->{snaks}; |
42
|
0
|
|
|
|
|
|
for my $snaks (values %{$r->{snaks}}) { |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
for my $snak (@$snaks) { |
44
|
0
|
|
|
|
|
|
simplify_snak($snak); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$data; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |