line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use base qw(Exporter); |
3
|
4
|
|
|
4
|
|
396494
|
use strict; |
|
4
|
|
|
|
|
37
|
|
|
4
|
|
|
|
|
361
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
54
|
|
5
|
4
|
|
|
4
|
|
14
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
85
|
|
6
|
|
|
|
|
|
|
use Error::Pure qw(err); |
7
|
4
|
|
|
4
|
|
931
|
use Readonly; |
|
4
|
|
|
|
|
16328
|
|
|
4
|
|
|
|
|
69
|
|
8
|
4
|
|
|
4
|
|
118
|
use Wikibase::Datatype::Property; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
93
|
|
9
|
4
|
|
|
4
|
|
1378
|
use Wikibase::Datatype::Struct::Language; |
|
4
|
|
|
|
|
12659
|
|
|
4
|
|
|
|
|
86
|
|
10
|
4
|
|
|
4
|
|
1179
|
use Wikibase::Datatype::Struct::Statement; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
164
|
|
11
|
4
|
|
|
4
|
|
1388
|
use Wikibase::Datatype::Struct::Value::Monolingual; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
130
|
|
12
|
4
|
|
|
4
|
|
20
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
2234
|
|
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.09; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my ($obj, $base_uri) = @_; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
1
|
8897
|
if (! defined $obj) { |
20
|
|
|
|
|
|
|
err "Object doesn't exist."; |
21
|
6
|
100
|
|
|
|
16
|
} |
22
|
1
|
|
|
|
|
3
|
if (! $obj->isa('Wikibase::Datatype::Property')) { |
23
|
|
|
|
|
|
|
err "Object isn't 'Wikibase::Datatype::Property'."; |
24
|
5
|
100
|
|
|
|
22
|
} |
25
|
1
|
|
|
|
|
4
|
if (! defined $base_uri) { |
26
|
|
|
|
|
|
|
err 'Base URI is required.'; |
27
|
4
|
100
|
|
|
|
9
|
} |
28
|
1
|
|
|
|
|
39
|
|
29
|
|
|
|
|
|
|
my $struct_hr = { |
30
|
|
|
|
|
|
|
'type' => 'property', |
31
|
3
|
|
|
|
|
6
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Aliases. |
34
|
|
|
|
|
|
|
foreach my $alias (@{$obj->aliases}) { |
35
|
|
|
|
|
|
|
if (! exists $struct_hr->{'aliases'}->{$alias->language}) { |
36
|
3
|
|
|
|
|
5
|
$struct_hr->{'aliases'}->{$alias->language} = []; |
|
3
|
|
|
|
|
7
|
|
37
|
2
|
100
|
|
|
|
12
|
} |
38
|
1
|
|
|
|
|
9
|
push @{$struct_hr->{'aliases'}->{$alias->language}}, |
39
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Language::obj2struct($alias); |
40
|
2
|
|
|
|
|
11
|
} |
|
2
|
|
|
|
|
4
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Claims. |
43
|
|
|
|
|
|
|
foreach my $statement (@{$obj->statements}) { |
44
|
|
|
|
|
|
|
$struct_hr->{'claims'}->{$statement->snak->property} //= []; |
45
|
3
|
|
|
|
|
16
|
push @{$struct_hr->{'claims'}->{$statement->snak->property}}, |
|
3
|
|
|
|
|
8
|
|
46
|
1
|
|
50
|
|
|
10
|
Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri); |
47
|
1
|
|
|
|
|
22
|
} |
|
1
|
|
|
|
|
4
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Datatype. |
50
|
|
|
|
|
|
|
$struct_hr->{'datatype'} = $obj->datatype; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
18
|
# Descriptions. |
53
|
|
|
|
|
|
|
foreach my $desc (@{$obj->descriptions}) { |
54
|
|
|
|
|
|
|
$struct_hr->{'descriptions'}->{$desc->language} |
55
|
3
|
|
|
|
|
16
|
= Wikibase::Datatype::Struct::Language::obj2struct($desc); |
|
3
|
|
|
|
|
5
|
|
56
|
1
|
|
|
|
|
10
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Id. |
59
|
|
|
|
|
|
|
if (defined $obj->id) { |
60
|
|
|
|
|
|
|
$struct_hr->{'id'} = $obj->id; |
61
|
3
|
100
|
|
|
|
20
|
} |
62
|
1
|
|
|
|
|
7
|
|
63
|
|
|
|
|
|
|
# Labels. |
64
|
|
|
|
|
|
|
foreach my $label (@{$obj->labels}) { |
65
|
|
|
|
|
|
|
$struct_hr->{'labels'}->{$label->language} |
66
|
3
|
|
|
|
|
14
|
= Wikibase::Datatype::Struct::Language::obj2struct($label); |
|
3
|
|
|
|
|
6
|
|
67
|
1
|
|
|
|
|
8
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Last revision id. |
70
|
|
|
|
|
|
|
if (defined $obj->lastrevid) { |
71
|
|
|
|
|
|
|
$struct_hr->{'lastrevid'} = $obj->lastrevid; |
72
|
3
|
100
|
|
|
|
18
|
} |
73
|
1
|
|
|
|
|
6
|
|
74
|
|
|
|
|
|
|
# Modified date. |
75
|
|
|
|
|
|
|
if (defined $obj->modified) { |
76
|
|
|
|
|
|
|
$struct_hr->{'modified'} = $obj->modified; |
77
|
3
|
100
|
|
|
|
18
|
} |
78
|
1
|
|
|
|
|
7
|
|
79
|
|
|
|
|
|
|
# Namespace. |
80
|
|
|
|
|
|
|
if (defined $obj->ns) { |
81
|
|
|
|
|
|
|
$struct_hr->{'ns'} = $obj->ns; |
82
|
3
|
100
|
|
|
|
19
|
} |
83
|
2
|
|
|
|
|
17
|
|
84
|
|
|
|
|
|
|
# Page ID. |
85
|
|
|
|
|
|
|
if (defined $obj->page_id) { |
86
|
|
|
|
|
|
|
$struct_hr->{'pageid'} = $obj->page_id; |
87
|
3
|
100
|
|
|
|
20
|
} |
88
|
1
|
|
|
|
|
5
|
|
89
|
|
|
|
|
|
|
# Title. |
90
|
|
|
|
|
|
|
if (defined $obj->title) { |
91
|
|
|
|
|
|
|
$struct_hr->{'title'} = $obj->title; |
92
|
3
|
100
|
|
|
|
18
|
} |
93
|
1
|
|
|
|
|
7
|
|
94
|
|
|
|
|
|
|
return $struct_hr; |
95
|
|
|
|
|
|
|
} |
96
|
3
|
|
|
|
|
23
|
|
97
|
|
|
|
|
|
|
my $struct_hr = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if (! exists $struct_hr->{'type'} || $struct_hr->{'type'} ne 'property') { |
100
|
5
|
|
|
5
|
1
|
10045
|
err "Structure isn't for 'property' type."; |
101
|
|
|
|
|
|
|
} |
102
|
5
|
100
|
100
|
|
|
23
|
|
103
|
2
|
|
|
|
|
7
|
# Aliases. |
104
|
|
|
|
|
|
|
my $aliases_ar = []; |
105
|
|
|
|
|
|
|
foreach my $lang (keys %{$struct_hr->{'aliases'}}) { |
106
|
|
|
|
|
|
|
foreach my $alias_hr (@{$struct_hr->{'aliases'}->{$lang}}) { |
107
|
3
|
|
|
|
|
5
|
push @{$aliases_ar}, Wikibase::Datatype::Struct::Language::struct2obj( |
108
|
3
|
|
|
|
|
5
|
$alias_hr, |
|
3
|
|
|
|
|
8
|
|
109
|
1
|
|
|
|
|
3
|
); |
|
1
|
|
|
|
|
3
|
|
110
|
2
|
|
|
|
|
4
|
} |
|
2
|
|
|
|
|
6
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Descriptions. |
114
|
|
|
|
|
|
|
my $descriptions_ar = []; |
115
|
|
|
|
|
|
|
foreach my $lang (keys %{$struct_hr->{'descriptions'}}) { |
116
|
|
|
|
|
|
|
push @{$descriptions_ar}, Wikibase::Datatype::Struct::Language::struct2obj( |
117
|
3
|
|
|
|
|
6
|
$struct_hr->{'descriptions'}->{$lang}, |
118
|
3
|
|
|
|
|
4
|
); |
|
3
|
|
|
|
|
7
|
|
119
|
1
|
|
|
|
|
4
|
} |
120
|
1
|
|
|
|
|
2
|
|
121
|
|
|
|
|
|
|
# Labels. |
122
|
|
|
|
|
|
|
my $labels_ar = []; |
123
|
|
|
|
|
|
|
foreach my $lang (keys %{$struct_hr->{'labels'}}) { |
124
|
|
|
|
|
|
|
push @{$labels_ar}, Wikibase::Datatype::Struct::Language::struct2obj( |
125
|
3
|
|
|
|
|
4
|
$struct_hr->{'labels'}->{$lang}, |
126
|
3
|
|
|
|
|
4
|
); |
|
3
|
|
|
|
|
8
|
|
127
|
1
|
|
|
|
|
5
|
} |
128
|
1
|
|
|
|
|
2
|
|
129
|
|
|
|
|
|
|
# Statements. |
130
|
|
|
|
|
|
|
my $statements_ar = []; |
131
|
|
|
|
|
|
|
foreach my $property (keys %{$struct_hr->{'claims'}}) { |
132
|
|
|
|
|
|
|
foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) { |
133
|
3
|
|
|
|
|
5
|
push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj( |
134
|
3
|
|
|
|
|
4
|
$claim_hr, |
|
3
|
|
|
|
|
8
|
|
135
|
1
|
|
|
|
|
2
|
); |
|
1
|
|
|
|
|
3
|
|
136
|
1
|
|
|
|
|
2
|
} |
|
1
|
|
|
|
|
4
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Property->new( |
140
|
|
|
|
|
|
|
'aliases' => $aliases_ar, |
141
|
|
|
|
|
|
|
'datatype' => $struct_hr->{'datatype'}, |
142
|
|
|
|
|
|
|
'descriptions' => $descriptions_ar, |
143
|
|
|
|
|
|
|
defined $struct_hr->{'id'} ? ('id' => $struct_hr->{'id'}) : (), |
144
|
|
|
|
|
|
|
'labels' => $labels_ar, |
145
|
|
|
|
|
|
|
defined $struct_hr->{'lastrevid'} ? ('lastrevid' => $struct_hr->{'lastrevid'}) : (), |
146
|
|
|
|
|
|
|
defined $struct_hr->{'modified'} ? ('modified' => $struct_hr->{'modified'}) : (), |
147
|
|
|
|
|
|
|
defined $struct_hr->{'ns'} ? ('ns' => $struct_hr->{'ns'}) : (), |
148
|
|
|
|
|
|
|
defined $struct_hr->{'pageid'} ? ('page_id' => $struct_hr->{'pageid'}) : (), |
149
|
|
|
|
|
|
|
'statements' => $statements_ar, |
150
|
|
|
|
|
|
|
defined $struct_hr->{'title'} ? ('title' => $struct_hr->{'title'}) : (), |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
3
|
100
|
|
|
|
31
|
return $obj; |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
3
|
|
|
|
|
535
|
1; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=pod |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=encoding utf8 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 NAME |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Property - Wikibase property structure serialization. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SYNOPSIS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Property qw(obj2struct struct2obj); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
172
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 DESCRIPTION |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
177
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 SUBROUTINES |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 C<obj2struct> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Property instance to structure. |
186
|
|
|
|
|
|
|
C<$base_uri> is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/). |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Returns reference to hash with structure. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 C<struct2obj> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Convert structure of property to object. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Property instance. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 ERRORS |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
obj2struct(): |
201
|
|
|
|
|
|
|
Base URI is required. |
202
|
|
|
|
|
|
|
Object doesn't exist. |
203
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Property'. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
struct2obj(): |
206
|
|
|
|
|
|
|
Structure isn't for 'property' type. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
use strict; |
211
|
|
|
|
|
|
|
use warnings; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
use Data::Printer; |
214
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8); |
215
|
|
|
|
|
|
|
use Wikibase::Datatype::Property; |
216
|
|
|
|
|
|
|
use Wikibase::Datatype::Reference; |
217
|
|
|
|
|
|
|
use Wikibase::Datatype::Sitelink; |
218
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
219
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
220
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Property qw(obj2struct); |
221
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
222
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
223
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
224
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# Statement. |
227
|
|
|
|
|
|
|
my $statement1 = Wikibase::Datatype::Statement->new( |
228
|
|
|
|
|
|
|
# instance of (P31) Wikidata property (Q18616576) |
229
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
230
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
231
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
232
|
|
|
|
|
|
|
'value' => 'Q18616576', |
233
|
|
|
|
|
|
|
), |
234
|
|
|
|
|
|
|
'property' => 'P31', |
235
|
|
|
|
|
|
|
), |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Main property. |
239
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Property->new( |
240
|
|
|
|
|
|
|
'aliases' => [ |
241
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
242
|
|
|
|
|
|
|
'language' => 'cs', |
243
|
|
|
|
|
|
|
'value' => 'je', |
244
|
|
|
|
|
|
|
), |
245
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
246
|
|
|
|
|
|
|
'language' => 'en', |
247
|
|
|
|
|
|
|
'value' => 'is a', |
248
|
|
|
|
|
|
|
), |
249
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
250
|
|
|
|
|
|
|
'language' => 'en', |
251
|
|
|
|
|
|
|
'value' => 'is an', |
252
|
|
|
|
|
|
|
), |
253
|
|
|
|
|
|
|
], |
254
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
255
|
|
|
|
|
|
|
'descriptions' => [ |
256
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
257
|
|
|
|
|
|
|
'language' => 'cs', |
258
|
|
|
|
|
|
|
'value' => decode_utf8('tato položka je jedna konkrétní věc (exemplář, '. |
259
|
|
|
|
|
|
|
'příklad) patřící do této třídy, kategorie nebo skupiny předmětů'), |
260
|
|
|
|
|
|
|
), |
261
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
262
|
|
|
|
|
|
|
'language' => 'en', |
263
|
|
|
|
|
|
|
'value' => 'that class of which this subject is a particular example and member', |
264
|
|
|
|
|
|
|
), |
265
|
|
|
|
|
|
|
], |
266
|
|
|
|
|
|
|
'id' => 'P31', |
267
|
|
|
|
|
|
|
'labels' => [ |
268
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
269
|
|
|
|
|
|
|
'language' => 'cs', |
270
|
|
|
|
|
|
|
'value' => decode_utf8('instance (čeho)'), |
271
|
|
|
|
|
|
|
), |
272
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
273
|
|
|
|
|
|
|
'language' => 'en', |
274
|
|
|
|
|
|
|
'value' => 'instance of', |
275
|
|
|
|
|
|
|
), |
276
|
|
|
|
|
|
|
], |
277
|
|
|
|
|
|
|
'page_id' => 3918489, |
278
|
|
|
|
|
|
|
'statements' => [ |
279
|
|
|
|
|
|
|
$statement1, |
280
|
|
|
|
|
|
|
], |
281
|
|
|
|
|
|
|
'title' => 'Property:P31', |
282
|
|
|
|
|
|
|
); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# Get structure. |
285
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# Dump to output. |
288
|
|
|
|
|
|
|
p $struct_hr; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# Output: |
291
|
|
|
|
|
|
|
# { |
292
|
|
|
|
|
|
|
# aliases { |
293
|
|
|
|
|
|
|
# cs [ |
294
|
|
|
|
|
|
|
# [0] { |
295
|
|
|
|
|
|
|
# language "cs", |
296
|
|
|
|
|
|
|
# value "je" |
297
|
|
|
|
|
|
|
# } |
298
|
|
|
|
|
|
|
# ], |
299
|
|
|
|
|
|
|
# en [ |
300
|
|
|
|
|
|
|
# [0] { |
301
|
|
|
|
|
|
|
# language "en", |
302
|
|
|
|
|
|
|
# value "is a" |
303
|
|
|
|
|
|
|
# }, |
304
|
|
|
|
|
|
|
# [1] { |
305
|
|
|
|
|
|
|
# language "en", |
306
|
|
|
|
|
|
|
# value "is an" |
307
|
|
|
|
|
|
|
# } |
308
|
|
|
|
|
|
|
# ] |
309
|
|
|
|
|
|
|
# }, |
310
|
|
|
|
|
|
|
# claims { |
311
|
|
|
|
|
|
|
# P31 [ |
312
|
|
|
|
|
|
|
# [0] { |
313
|
|
|
|
|
|
|
# mainsnak { |
314
|
|
|
|
|
|
|
# datatype "wikibase-item", |
315
|
|
|
|
|
|
|
# datavalue { |
316
|
|
|
|
|
|
|
# type "wikibase-entityid", |
317
|
|
|
|
|
|
|
# value { |
318
|
|
|
|
|
|
|
# entity-type "item", |
319
|
|
|
|
|
|
|
# id "Q18616576", |
320
|
|
|
|
|
|
|
# numeric-id 18616576 |
321
|
|
|
|
|
|
|
# } |
322
|
|
|
|
|
|
|
# }, |
323
|
|
|
|
|
|
|
# property "P31", |
324
|
|
|
|
|
|
|
# snaktype "value" |
325
|
|
|
|
|
|
|
# }, |
326
|
|
|
|
|
|
|
# rank "normal", |
327
|
|
|
|
|
|
|
# type "statement" |
328
|
|
|
|
|
|
|
# } |
329
|
|
|
|
|
|
|
# ] |
330
|
|
|
|
|
|
|
# }, |
331
|
|
|
|
|
|
|
# datatype "wikibase-item", |
332
|
|
|
|
|
|
|
# descriptions { |
333
|
|
|
|
|
|
|
# cs { |
334
|
|
|
|
|
|
|
# language "cs", |
335
|
|
|
|
|
|
|
# value "tato položka je jedna konkrétní věc (exemplář, příklad) patřící do této třídy, kategorie nebo skupiny předmětů" |
336
|
|
|
|
|
|
|
# }, |
337
|
|
|
|
|
|
|
# en { |
338
|
|
|
|
|
|
|
# language "en", |
339
|
|
|
|
|
|
|
# value "that class of which this subject is a particular example and member" |
340
|
|
|
|
|
|
|
# } |
341
|
|
|
|
|
|
|
# }, |
342
|
|
|
|
|
|
|
# id "P31", |
343
|
|
|
|
|
|
|
# labels { |
344
|
|
|
|
|
|
|
# cs { |
345
|
|
|
|
|
|
|
# language "cs", |
346
|
|
|
|
|
|
|
# value "instance (čeho)" |
347
|
|
|
|
|
|
|
# }, |
348
|
|
|
|
|
|
|
# en { |
349
|
|
|
|
|
|
|
# language "en", |
350
|
|
|
|
|
|
|
# value "instance of" |
351
|
|
|
|
|
|
|
# } |
352
|
|
|
|
|
|
|
# }, |
353
|
|
|
|
|
|
|
# ns 120, |
354
|
|
|
|
|
|
|
# pageid 3918489, |
355
|
|
|
|
|
|
|
# title "Property:P31", |
356
|
|
|
|
|
|
|
# type "property" |
357
|
|
|
|
|
|
|
# } |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
use strict; |
362
|
|
|
|
|
|
|
use warnings; |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
use Data::Printer; |
365
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8); |
366
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Property qw(struct2obj); |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
# Item structure. |
369
|
|
|
|
|
|
|
my $struct_hr = { |
370
|
|
|
|
|
|
|
'aliases' => { |
371
|
|
|
|
|
|
|
'cs' => [{ |
372
|
|
|
|
|
|
|
'language' => 'cs', |
373
|
|
|
|
|
|
|
'value' => 'je', |
374
|
|
|
|
|
|
|
}], |
375
|
|
|
|
|
|
|
'en' => [{ |
376
|
|
|
|
|
|
|
'language' => 'en', |
377
|
|
|
|
|
|
|
'value' => 'is a', |
378
|
|
|
|
|
|
|
}, { |
379
|
|
|
|
|
|
|
'language' => 'en', |
380
|
|
|
|
|
|
|
'value' => 'is an', |
381
|
|
|
|
|
|
|
}], |
382
|
|
|
|
|
|
|
}, |
383
|
|
|
|
|
|
|
'claims' => { |
384
|
|
|
|
|
|
|
'P31' => [{ |
385
|
|
|
|
|
|
|
'mainsnak' => { |
386
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
387
|
|
|
|
|
|
|
'datavalue' => { |
388
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
389
|
|
|
|
|
|
|
'value' => { |
390
|
|
|
|
|
|
|
'entity-type' => 'item', |
391
|
|
|
|
|
|
|
'id' => 'Q18616576', |
392
|
|
|
|
|
|
|
'numeric-id' => 18616576, |
393
|
|
|
|
|
|
|
}, |
394
|
|
|
|
|
|
|
}, |
395
|
|
|
|
|
|
|
'property' => 'P31', |
396
|
|
|
|
|
|
|
'snaktype' => 'value', |
397
|
|
|
|
|
|
|
}, |
398
|
|
|
|
|
|
|
'rank' => 'normal', |
399
|
|
|
|
|
|
|
'type' => 'statement', |
400
|
|
|
|
|
|
|
}], |
401
|
|
|
|
|
|
|
}, |
402
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
403
|
|
|
|
|
|
|
'descriptions' => { |
404
|
|
|
|
|
|
|
'cs' => { |
405
|
|
|
|
|
|
|
'language' => 'cs', |
406
|
|
|
|
|
|
|
'value' => decode_utf8('tato položka je jedna konkrétní věc (exemplář, příklad) patřící do této třídy, kategorie nebo skupiny předmětů'), |
407
|
|
|
|
|
|
|
}, |
408
|
|
|
|
|
|
|
'en' => { |
409
|
|
|
|
|
|
|
'language' => 'en', |
410
|
|
|
|
|
|
|
'value' => 'that class of which this subject is a particular example and member', |
411
|
|
|
|
|
|
|
}, |
412
|
|
|
|
|
|
|
}, |
413
|
|
|
|
|
|
|
'id' => 'P31', |
414
|
|
|
|
|
|
|
'labels' => { |
415
|
|
|
|
|
|
|
'cs' => { |
416
|
|
|
|
|
|
|
'language' => 'cs', |
417
|
|
|
|
|
|
|
'value' => decode_utf8('instance (čeho)'), |
418
|
|
|
|
|
|
|
}, |
419
|
|
|
|
|
|
|
'en' => { |
420
|
|
|
|
|
|
|
'language' => 'en', |
421
|
|
|
|
|
|
|
'value' => 'instance of', |
422
|
|
|
|
|
|
|
}, |
423
|
|
|
|
|
|
|
}, |
424
|
|
|
|
|
|
|
'ns' => 120, |
425
|
|
|
|
|
|
|
'pageid' => 3918489, |
426
|
|
|
|
|
|
|
'title' => 'Property:P31', |
427
|
|
|
|
|
|
|
'type' => 'property', |
428
|
|
|
|
|
|
|
}; |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
# Get object. |
431
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
# Print out. |
434
|
|
|
|
|
|
|
p $obj; |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
# Output: |
437
|
|
|
|
|
|
|
# Wikibase::Datatype::Property { |
438
|
|
|
|
|
|
|
# parents: Mo::Object |
439
|
|
|
|
|
|
|
# public methods (8): |
440
|
|
|
|
|
|
|
# BUILD |
441
|
|
|
|
|
|
|
# Error::Pure: |
442
|
|
|
|
|
|
|
# err |
443
|
|
|
|
|
|
|
# List::Util: |
444
|
|
|
|
|
|
|
# none |
445
|
|
|
|
|
|
|
# Mo::utils: |
446
|
|
|
|
|
|
|
# check_array_object, check_number, check_number_of_items, check_required |
447
|
|
|
|
|
|
|
# Readonly: |
448
|
|
|
|
|
|
|
# Readonly |
449
|
|
|
|
|
|
|
# private methods (0) |
450
|
|
|
|
|
|
|
# internals: { |
451
|
|
|
|
|
|
|
# aliases [ |
452
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Value::Monolingual, |
453
|
|
|
|
|
|
|
# [1] Wikibase::Datatype::Value::Monolingual, |
454
|
|
|
|
|
|
|
# [2] Wikibase::Datatype::Value::Monolingual |
455
|
|
|
|
|
|
|
# ], |
456
|
|
|
|
|
|
|
# datatype "wikibase-item", |
457
|
|
|
|
|
|
|
# descriptions [ |
458
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Value::Monolingual, |
459
|
|
|
|
|
|
|
# [1] Wikibase::Datatype::Value::Monolingual |
460
|
|
|
|
|
|
|
# ], |
461
|
|
|
|
|
|
|
# id "P31", |
462
|
|
|
|
|
|
|
# labels [ |
463
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Value::Monolingual, |
464
|
|
|
|
|
|
|
# [1] Wikibase::Datatype::Value::Monolingual |
465
|
|
|
|
|
|
|
# ], |
466
|
|
|
|
|
|
|
# ns 120, |
467
|
|
|
|
|
|
|
# page_id 3918489, |
468
|
|
|
|
|
|
|
# statements [ |
469
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Statement |
470
|
|
|
|
|
|
|
# ], |
471
|
|
|
|
|
|
|
# title "Property:P31" |
472
|
|
|
|
|
|
|
# } |
473
|
|
|
|
|
|
|
# } |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
L<Error::Pure>, |
478
|
|
|
|
|
|
|
L<Exporter>, |
479
|
|
|
|
|
|
|
L<Readonly>, |
480
|
|
|
|
|
|
|
L<Wikibase::Datatype::Item>, |
481
|
|
|
|
|
|
|
L<Wikibase::Datatype::Reference>, |
482
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Language>, |
483
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Statement>, |
484
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Monolingual>. |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=head1 SEE ALSO |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=over |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
Wikibase structure serialization. |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Item> |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Wikibase item datatype. |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=back |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=head1 REPOSITORY |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=head1 AUTHOR |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
L<http://skim.cz> |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
© 2020-2022 Michal Josef Špaček |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
BSD 2-Clause License |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=head1 VERSION |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
0.09 |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=cut |