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