line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikidata::Reconcilation; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
225050
|
use strict; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
89
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1600
|
use Class::Utils qw(set_params); |
|
3
|
|
|
|
|
40583
|
|
|
3
|
|
|
|
|
60
|
|
7
|
3
|
|
|
3
|
|
201
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
113
|
|
8
|
3
|
|
|
3
|
|
2367
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
171593
|
|
|
3
|
|
|
|
|
180
|
|
9
|
3
|
|
|
3
|
|
1435
|
use Unicode::UTF8 qw(encode_utf8); |
|
3
|
|
|
|
|
1667
|
|
|
3
|
|
|
|
|
170
|
|
10
|
3
|
|
|
3
|
|
1443
|
use WQS::SPARQL; |
|
3
|
|
|
|
|
25001
|
|
|
3
|
|
|
|
|
97
|
|
11
|
3
|
|
|
3
|
|
1405
|
use WQS::SPARQL::Result; |
|
3
|
|
|
|
|
1727
|
|
|
3
|
|
|
|
|
1763
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.03; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
1
|
104
|
my ($class, @params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Create object. |
20
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# User agent. |
23
|
1
|
|
|
|
|
23
|
$self->{'agent'} = __PACKAGE__." ($VERSION)"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# First match mode. |
26
|
1
|
|
|
|
|
4
|
$self->{'first_match'} = 0; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Language. |
29
|
1
|
|
|
|
|
3
|
$self->{'language'} = 'en'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# LWP::UserAgent object. |
32
|
1
|
|
|
|
|
3
|
$self->{'lwp_user_agent'} = undef; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Verbose mode. |
35
|
1
|
|
|
|
|
4
|
$self->{'verbose'} = 0; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Process parameters. |
38
|
1
|
|
|
|
|
5
|
set_params($self, @params); |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
26
|
if (! defined $self->{'lwp_user_agent'}) { |
41
|
|
|
|
|
|
|
$self->{'lwp_user_agent'} = LWP::UserAgent->new( |
42
|
1
|
|
|
|
|
9
|
'agent' => $self->{'agent'}, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
0
|
|
|
|
0
|
if (! $self->{'lwp_user_agent'}->isa('LWP::UserAgent')) { |
46
|
0
|
|
|
|
|
0
|
err "Parameter 'lwp_user_agent' must be a 'LWP::UserAgent' instance."; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->{'_q'} = WQS::SPARQL->new( |
51
|
1
|
|
|
|
|
3258
|
'lwp_user_agent' => $self->{'lwp_user_agent'}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
68
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub reconcile { |
58
|
0
|
|
|
0
|
1
|
|
my ($self, $reconcilation_rules_hr) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my @sparql = $self->_reconcile($reconcilation_rules_hr); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $ret_hr; |
63
|
|
|
|
|
|
|
my %qids; |
64
|
0
|
0
|
|
|
|
|
if ($self->{'verbose'}) { |
65
|
0
|
|
|
|
|
|
print "SPARQL queries:\n"; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
foreach my $sparql (@sparql) { |
68
|
0
|
0
|
|
|
|
|
if ($self->{'verbose'}) { |
69
|
0
|
|
|
|
|
|
print encode_utf8($sparql)."\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$ret_hr = $self->{'_q'}->query($sparql); |
73
|
0
|
|
|
|
|
|
my @ret = map { $_->{'item'} } WQS::SPARQL::Result->new( |
74
|
0
|
|
|
|
|
|
'verbose' => $self->{'verbose'}, |
75
|
|
|
|
|
|
|
)->result($ret_hr); |
76
|
0
|
|
|
|
|
|
foreach my $ret (@ret) { |
77
|
0
|
|
|
|
|
|
$qids{$ret}++; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
0
|
0
|
|
|
|
if (@ret && $self->{'first_match'}) { |
80
|
0
|
|
|
|
|
|
last; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
|
if ($self->{'verbose'}) { |
84
|
0
|
|
|
|
|
|
print "Results:\n"; |
85
|
0
|
|
|
|
|
|
foreach my $item (sort keys %qids) { |
86
|
0
|
|
|
|
|
|
print '- '.$item.': '.$qids{$item}."\n"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return sort keys %qids; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _reconcile { |
94
|
0
|
|
|
0
|
|
|
my ($self, $reconcilation_rules_hr) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
err "This is abstract class. You need to implement _reconcile() method."; |
97
|
0
|
|
|
|
|
|
my @sparql; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return @sparql; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _exists_id { |
103
|
0
|
|
|
0
|
|
|
my ($self, $reconcilation_rules_hr, $id) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
0
|
|
|
|
if (exists $reconcilation_rules_hr->{'identifiers'}->{$id} |
106
|
|
|
|
|
|
|
&& defined $reconcilation_rules_hr->{'identifiers'}->{$id}) { |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return 1; |
109
|
|
|
|
|
|
|
} else { |
110
|
0
|
|
|
|
|
|
return 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |