| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use base qw(Exporter); |
|
3
|
4
|
|
|
4
|
|
414864
|
use strict; |
|
|
4
|
|
|
|
|
42
|
|
|
|
4
|
|
|
|
|
386
|
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
|
4
|
|
|
|
|
4
|
|
|
|
4
|
|
|
|
|
67
|
|
|
5
|
4
|
|
|
4
|
|
15
|
|
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
85
|
|
|
6
|
|
|
|
|
|
|
use Error::Pure qw(err); |
|
7
|
4
|
|
|
4
|
|
960
|
use Readonly; |
|
|
4
|
|
|
|
|
17230
|
|
|
|
4
|
|
|
|
|
71
|
|
|
8
|
4
|
|
|
4
|
|
139
|
use Wikibase::Datatype::Form; |
|
|
4
|
|
|
|
|
5
|
|
|
|
4
|
|
|
|
|
95
|
|
|
9
|
4
|
|
|
4
|
|
1079
|
use Wikibase::Datatype::Lexeme; |
|
|
4
|
|
|
|
|
11643
|
|
|
|
4
|
|
|
|
|
89
|
|
|
10
|
4
|
|
|
4
|
|
1133
|
use Wikibase::Datatype::Struct::Form; |
|
|
4
|
|
|
|
|
460724
|
|
|
|
4
|
|
|
|
|
266
|
|
|
11
|
4
|
|
|
4
|
|
1732
|
use Wikibase::Datatype::Struct::Language; |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
137
|
|
|
12
|
4
|
|
|
4
|
|
22
|
use Wikibase::Datatype::Struct::Sense; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
92
|
|
|
13
|
4
|
|
|
4
|
|
1426
|
use Wikibase::Datatype::Struct::Statement; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
131
|
|
|
14
|
4
|
|
|
4
|
|
22
|
use Wikibase::Datatype::Value::Item; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
90
|
|
|
15
|
4
|
|
|
4
|
|
17
|
|
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
2288
|
|
|
16
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.09; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my ($obj, $base_uri) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
7
|
|
|
7
|
1
|
15695
|
if (! defined $obj) { |
|
23
|
|
|
|
|
|
|
err "Object doesn't exist."; |
|
24
|
7
|
100
|
|
|
|
17
|
} |
|
25
|
1
|
|
|
|
|
5
|
if (! $obj->isa('Wikibase::Datatype::Lexeme')) { |
|
26
|
|
|
|
|
|
|
err "Object isn't 'Wikibase::Datatype::Lexeme'."; |
|
27
|
6
|
100
|
|
|
|
22
|
} |
|
28
|
1
|
|
|
|
|
4
|
if (! defined $base_uri) { |
|
29
|
|
|
|
|
|
|
err 'Base URI is required.'; |
|
30
|
5
|
100
|
|
|
|
10
|
} |
|
31
|
1
|
|
|
|
|
4
|
|
|
32
|
|
|
|
|
|
|
my $struct_hr = { |
|
33
|
|
|
|
|
|
|
'type' => 'lexeme', |
|
34
|
4
|
|
|
|
|
9
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Forms. |
|
37
|
|
|
|
|
|
|
foreach my $form (@{$obj->forms}) { |
|
38
|
|
|
|
|
|
|
$struct_hr->{'forms'} //= []; |
|
39
|
4
|
|
|
|
|
5
|
push @{$struct_hr->{'forms'}}, |
|
|
4
|
|
|
|
|
14
|
|
|
40
|
1
|
|
50
|
|
|
13
|
Wikibase::Datatype::Struct::Form::obj2struct($form, $base_uri); |
|
41
|
1
|
|
|
|
|
2
|
} |
|
|
1
|
|
|
|
|
4
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Id. |
|
44
|
|
|
|
|
|
|
if (defined $obj->id) { |
|
45
|
|
|
|
|
|
|
$struct_hr->{'id'} = $obj->id; |
|
46
|
4
|
100
|
|
|
|
110
|
} |
|
47
|
1
|
|
|
|
|
18
|
|
|
48
|
|
|
|
|
|
|
# Last revision id. |
|
49
|
|
|
|
|
|
|
if (defined $obj->lastrevid) { |
|
50
|
|
|
|
|
|
|
$struct_hr->{'lastrevid'} = $obj->lastrevid; |
|
51
|
4
|
100
|
|
|
|
28
|
} |
|
52
|
1
|
|
|
|
|
7
|
|
|
53
|
|
|
|
|
|
|
# Language. |
|
54
|
|
|
|
|
|
|
if (defined $obj->language) { |
|
55
|
|
|
|
|
|
|
$struct_hr->{'language'} = $obj->language; |
|
56
|
4
|
100
|
|
|
|
21
|
} |
|
57
|
1
|
|
|
|
|
6
|
|
|
58
|
|
|
|
|
|
|
# Lemmas. |
|
59
|
|
|
|
|
|
|
foreach my $lemma (@{$obj->lemmas}) { |
|
60
|
|
|
|
|
|
|
$struct_hr->{'lemmas'}->{$lemma->language} |
|
61
|
4
|
|
|
|
|
17
|
= Wikibase::Datatype::Struct::Language::obj2struct($lemma); |
|
|
4
|
|
|
|
|
9
|
|
|
62
|
1
|
|
|
|
|
7
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Lexical category. |
|
65
|
|
|
|
|
|
|
if (defined $obj->lexical_category) { |
|
66
|
|
|
|
|
|
|
$struct_hr->{'lexicalCategory'} = $obj->lexical_category; |
|
67
|
4
|
100
|
|
|
|
25
|
} |
|
68
|
1
|
|
|
|
|
6
|
|
|
69
|
|
|
|
|
|
|
# Modified date. |
|
70
|
|
|
|
|
|
|
if (defined $obj->modified) { |
|
71
|
|
|
|
|
|
|
$struct_hr->{'modified'} = $obj->modified; |
|
72
|
4
|
100
|
|
|
|
23
|
} |
|
73
|
1
|
|
|
|
|
6
|
|
|
74
|
|
|
|
|
|
|
# Namespace. |
|
75
|
|
|
|
|
|
|
if (defined $obj->ns) { |
|
76
|
|
|
|
|
|
|
$struct_hr->{'ns'} = $obj->ns; |
|
77
|
4
|
100
|
|
|
|
21
|
} |
|
78
|
3
|
|
|
|
|
22
|
|
|
79
|
|
|
|
|
|
|
# Page id. |
|
80
|
|
|
|
|
|
|
if (defined $obj->page_id) { |
|
81
|
|
|
|
|
|
|
$struct_hr->{'pageid'} = $obj->page_id; |
|
82
|
4
|
100
|
|
|
|
26
|
} |
|
83
|
1
|
|
|
|
|
5
|
|
|
84
|
|
|
|
|
|
|
# Senses. |
|
85
|
|
|
|
|
|
|
foreach my $sense (@{$obj->senses}) { |
|
86
|
|
|
|
|
|
|
$struct_hr->{'senses'} //= []; |
|
87
|
4
|
|
|
|
|
18
|
push @{$struct_hr->{'senses'}}, |
|
|
4
|
|
|
|
|
8
|
|
|
88
|
1
|
|
50
|
|
|
10
|
Wikibase::Datatype::Struct::Sense::obj2struct($sense, $base_uri); |
|
89
|
1
|
|
|
|
|
2
|
} |
|
|
1
|
|
|
|
|
3
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Statements. |
|
92
|
|
|
|
|
|
|
foreach my $statement (@{$obj->statements}) { |
|
93
|
|
|
|
|
|
|
$struct_hr->{'claims'}->{$statement->snak->property} //= []; |
|
94
|
4
|
|
|
|
|
17
|
push @{$struct_hr->{'claims'}->{$statement->snak->property}}, |
|
|
4
|
|
|
|
|
9
|
|
|
95
|
3
|
|
100
|
|
|
18
|
Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri); |
|
96
|
3
|
|
|
|
|
29
|
} |
|
|
3
|
|
|
|
|
4
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Title. |
|
99
|
|
|
|
|
|
|
if (defined $obj->title) { |
|
100
|
|
|
|
|
|
|
$struct_hr->{'title'} = $obj->title; |
|
101
|
4
|
100
|
|
|
|
18
|
} |
|
102
|
1
|
|
|
|
|
7
|
|
|
103
|
|
|
|
|
|
|
return $struct_hr; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
4
|
|
|
|
|
37
|
|
|
106
|
|
|
|
|
|
|
my $struct_hr = shift; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if (! exists $struct_hr->{'type'} || $struct_hr->{'type'} ne 'lexeme') { |
|
109
|
5
|
|
|
5
|
1
|
9507
|
err "Structure isn't for 'lexeme' type."; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
5
|
100
|
100
|
|
|
45
|
|
|
112
|
2
|
|
|
|
|
10
|
# Forms. |
|
113
|
|
|
|
|
|
|
my $forms_ar = []; |
|
114
|
|
|
|
|
|
|
foreach my $form_hr (@{$struct_hr->{'forms'}}) { |
|
115
|
|
|
|
|
|
|
push @{$forms_ar}, Wikibase::Datatype::Struct::Form::struct2obj($form_hr); |
|
116
|
3
|
|
|
|
|
7
|
} |
|
117
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
10
|
|
|
118
|
1
|
|
|
|
|
2
|
# Lemmas. |
|
|
1
|
|
|
|
|
6
|
|
|
119
|
|
|
|
|
|
|
my $lemmas_ar = []; |
|
120
|
|
|
|
|
|
|
foreach my $lang (keys %{$struct_hr->{'lemmas'}}) { |
|
121
|
|
|
|
|
|
|
push @{$lemmas_ar}, Wikibase::Datatype::Struct::Language::struct2obj( |
|
122
|
3
|
|
|
|
|
7
|
$struct_hr->{'lemmas'}->{$lang}, |
|
123
|
3
|
|
|
|
|
5
|
); |
|
|
3
|
|
|
|
|
81
|
|
|
124
|
1
|
|
|
|
|
4
|
} |
|
125
|
1
|
|
|
|
|
2
|
|
|
126
|
|
|
|
|
|
|
# Senses. |
|
127
|
|
|
|
|
|
|
my $senses_ar = []; |
|
128
|
|
|
|
|
|
|
foreach my $sense_hr (@{$struct_hr->{'senses'}}) { |
|
129
|
|
|
|
|
|
|
push @{$senses_ar}, Wikibase::Datatype::Struct::Sense::struct2obj($sense_hr); |
|
130
|
3
|
|
|
|
|
8
|
} |
|
131
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
8
|
|
|
132
|
1
|
|
|
|
|
2
|
# Statements. |
|
|
1
|
|
|
|
|
5
|
|
|
133
|
|
|
|
|
|
|
my $statements_ar = []; |
|
134
|
|
|
|
|
|
|
foreach my $property (keys %{$struct_hr->{'claims'}}) { |
|
135
|
|
|
|
|
|
|
foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) { |
|
136
|
3
|
|
|
|
|
6
|
push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj( |
|
137
|
3
|
|
|
|
|
6
|
$claim_hr, |
|
|
3
|
|
|
|
|
9
|
|
|
138
|
1
|
|
|
|
|
2
|
); |
|
|
1
|
|
|
|
|
3
|
|
|
139
|
1
|
|
|
|
|
4
|
} |
|
|
1
|
|
|
|
|
4
|
|
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Lexeme->new( |
|
143
|
|
|
|
|
|
|
'forms' => $forms_ar, |
|
144
|
|
|
|
|
|
|
'id' => $struct_hr->{'id'}, |
|
145
|
|
|
|
|
|
|
'language' => $struct_hr->{'language'}, |
|
146
|
|
|
|
|
|
|
defined $struct_hr->{'lastrevid'} ? ('lastrevid' => $struct_hr->{'lastrevid'}) : (), |
|
147
|
|
|
|
|
|
|
'lemmas' => $lemmas_ar, |
|
148
|
|
|
|
|
|
|
defined $struct_hr->{'lexicalCategory'} ? ('lexical_category' => $struct_hr->{'lexicalCategory'}) : (), |
|
149
|
|
|
|
|
|
|
defined $struct_hr->{'modified'} ? ('modified' => $struct_hr->{'modified'}) : (), |
|
150
|
|
|
|
|
|
|
defined $struct_hr->{'ns'} ? ('ns' => $struct_hr->{'ns'}) : (), |
|
151
|
|
|
|
|
|
|
defined $struct_hr->{'pageid'} ? ('page_id' => $struct_hr->{'pageid'}) : (), |
|
152
|
|
|
|
|
|
|
'senses' => $senses_ar, |
|
153
|
|
|
|
|
|
|
'statements' => $statements_ar, |
|
154
|
|
|
|
|
|
|
defined $struct_hr->{'title'} ? ('title' => $struct_hr->{'title'}) : (), |
|
155
|
|
|
|
|
|
|
); |
|
156
|
|
|
|
|
|
|
|
|
157
|
3
|
100
|
|
|
|
63
|
return $obj; |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
3
|
|
|
|
|
453
|
1; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=pod |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=encoding utf8 |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 NAME |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Lexeme - Wikibase lexeme structure serialization. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Lexeme qw(obj2struct struct2obj); |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
|
176
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
|
181
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SUBROUTINES |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 C<obj2struct> |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Lexeme instance to structure. |
|
190
|
|
|
|
|
|
|
C<$base_uri> is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/). |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Returns reference to hash with structure. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 C<struct2obj> |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Convert structure of lexeme to object. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Lexeme instance. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 ERRORS |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
obj2struct(): |
|
205
|
|
|
|
|
|
|
Base URI is required. |
|
206
|
|
|
|
|
|
|
Object doesn't exist. |
|
207
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Form'. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
struct2obj(): |
|
210
|
|
|
|
|
|
|
Structure isn't for 'lexeme' type. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
use strict; |
|
215
|
|
|
|
|
|
|
use warnings; |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
use Data::Printer; |
|
218
|
|
|
|
|
|
|
use Wikibase::Datatype::Form; |
|
219
|
|
|
|
|
|
|
use Wikibase::Datatype::Lexeme; |
|
220
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
|
221
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Lexeme qw(obj2struct); |
|
222
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Statement. |
|
225
|
|
|
|
|
|
|
my $statement = Wikibase::Datatype::Statement->new( |
|
226
|
|
|
|
|
|
|
# instance of (P31) human (Q5) |
|
227
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
|
228
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
|
229
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
|
230
|
|
|
|
|
|
|
'value' => 'Q5', |
|
231
|
|
|
|
|
|
|
), |
|
232
|
|
|
|
|
|
|
'property' => 'P31', |
|
233
|
|
|
|
|
|
|
), |
|
234
|
|
|
|
|
|
|
); |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
# Form. |
|
237
|
|
|
|
|
|
|
my $form = Wikibase::Datatype::Form->new( |
|
238
|
|
|
|
|
|
|
'grammatical_features' => [ |
|
239
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Item->new( |
|
240
|
|
|
|
|
|
|
'value' => 'Q163012', |
|
241
|
|
|
|
|
|
|
), |
|
242
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Item->new( |
|
243
|
|
|
|
|
|
|
'value' => 'Q163014', |
|
244
|
|
|
|
|
|
|
), |
|
245
|
|
|
|
|
|
|
], |
|
246
|
|
|
|
|
|
|
'id' => 'ID', |
|
247
|
|
|
|
|
|
|
'representations' => [ |
|
248
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
|
249
|
|
|
|
|
|
|
'language' => 'en', |
|
250
|
|
|
|
|
|
|
'value' => 'Representation en', |
|
251
|
|
|
|
|
|
|
), |
|
252
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
|
253
|
|
|
|
|
|
|
'language' => 'cs', |
|
254
|
|
|
|
|
|
|
'value' => 'Representation cs', |
|
255
|
|
|
|
|
|
|
), |
|
256
|
|
|
|
|
|
|
], |
|
257
|
|
|
|
|
|
|
'statements' => [ |
|
258
|
|
|
|
|
|
|
$statement, |
|
259
|
|
|
|
|
|
|
], |
|
260
|
|
|
|
|
|
|
); |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# Sense. |
|
263
|
|
|
|
|
|
|
my $sense = Wikibase::Datatype::Sense->new( |
|
264
|
|
|
|
|
|
|
'glosses' => [ |
|
265
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
|
266
|
|
|
|
|
|
|
'language' => 'en', |
|
267
|
|
|
|
|
|
|
'value' => 'Glosse en', |
|
268
|
|
|
|
|
|
|
), |
|
269
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
|
270
|
|
|
|
|
|
|
'language' => 'cs', |
|
271
|
|
|
|
|
|
|
'value' => 'Glosse cs', |
|
272
|
|
|
|
|
|
|
), |
|
273
|
|
|
|
|
|
|
], |
|
274
|
|
|
|
|
|
|
'id' => 'ID', |
|
275
|
|
|
|
|
|
|
'statements' => [ |
|
276
|
|
|
|
|
|
|
$statement, |
|
277
|
|
|
|
|
|
|
], |
|
278
|
|
|
|
|
|
|
); |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
my $lexeme = Wikibase::Datatype::Lexeme->new( |
|
281
|
|
|
|
|
|
|
'forms' => [ |
|
282
|
|
|
|
|
|
|
$form, |
|
283
|
|
|
|
|
|
|
], |
|
284
|
|
|
|
|
|
|
'senses' => [ |
|
285
|
|
|
|
|
|
|
$sense, |
|
286
|
|
|
|
|
|
|
], |
|
287
|
|
|
|
|
|
|
'statements' => [ |
|
288
|
|
|
|
|
|
|
$statement, |
|
289
|
|
|
|
|
|
|
], |
|
290
|
|
|
|
|
|
|
); |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# Get structure. |
|
293
|
|
|
|
|
|
|
my $struct_hr = obj2struct($lexeme, 'http://test.wikidata.org/entity/'); |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# Dump to output. |
|
296
|
|
|
|
|
|
|
p $struct_hr; |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# Output: |
|
299
|
|
|
|
|
|
|
# \ { |
|
300
|
|
|
|
|
|
|
# claims { |
|
301
|
|
|
|
|
|
|
# P31 [ |
|
302
|
|
|
|
|
|
|
# [0] { |
|
303
|
|
|
|
|
|
|
# mainsnak { |
|
304
|
|
|
|
|
|
|
# datatype "wikibase-item", |
|
305
|
|
|
|
|
|
|
# datavalue { |
|
306
|
|
|
|
|
|
|
# type "wikibase-entityid", |
|
307
|
|
|
|
|
|
|
# value { |
|
308
|
|
|
|
|
|
|
# entity-type "item", |
|
309
|
|
|
|
|
|
|
# id "Q5", |
|
310
|
|
|
|
|
|
|
# numeric-id 5 |
|
311
|
|
|
|
|
|
|
# } |
|
312
|
|
|
|
|
|
|
# }, |
|
313
|
|
|
|
|
|
|
# property "P31", |
|
314
|
|
|
|
|
|
|
# snaktype "value" |
|
315
|
|
|
|
|
|
|
# }, |
|
316
|
|
|
|
|
|
|
# rank "normal", |
|
317
|
|
|
|
|
|
|
# type "statement" |
|
318
|
|
|
|
|
|
|
# } |
|
319
|
|
|
|
|
|
|
# ] |
|
320
|
|
|
|
|
|
|
# }, |
|
321
|
|
|
|
|
|
|
# forms [ |
|
322
|
|
|
|
|
|
|
# [0] { |
|
323
|
|
|
|
|
|
|
# claims { |
|
324
|
|
|
|
|
|
|
# P31 [ |
|
325
|
|
|
|
|
|
|
# [0] { |
|
326
|
|
|
|
|
|
|
# mainsnak { |
|
327
|
|
|
|
|
|
|
# datatype "wikibase-item", |
|
328
|
|
|
|
|
|
|
# datavalue { |
|
329
|
|
|
|
|
|
|
# type "wikibase-entityid", |
|
330
|
|
|
|
|
|
|
# value { |
|
331
|
|
|
|
|
|
|
# entity-type "item", |
|
332
|
|
|
|
|
|
|
# id "Q5", |
|
333
|
|
|
|
|
|
|
# numeric-id 5 |
|
334
|
|
|
|
|
|
|
# } |
|
335
|
|
|
|
|
|
|
# }, |
|
336
|
|
|
|
|
|
|
# property "P31", |
|
337
|
|
|
|
|
|
|
# snaktype "value" |
|
338
|
|
|
|
|
|
|
# }, |
|
339
|
|
|
|
|
|
|
# rank "normal", |
|
340
|
|
|
|
|
|
|
# type "statement" |
|
341
|
|
|
|
|
|
|
# } |
|
342
|
|
|
|
|
|
|
# ] |
|
343
|
|
|
|
|
|
|
# }, |
|
344
|
|
|
|
|
|
|
# grammaticalFeatures [ |
|
345
|
|
|
|
|
|
|
# [0] "Q163012", |
|
346
|
|
|
|
|
|
|
# [1] "Q163014" |
|
347
|
|
|
|
|
|
|
# ], |
|
348
|
|
|
|
|
|
|
# id "ID", |
|
349
|
|
|
|
|
|
|
# representations { |
|
350
|
|
|
|
|
|
|
# cs { |
|
351
|
|
|
|
|
|
|
# language "cs", |
|
352
|
|
|
|
|
|
|
# value "Representation cs" |
|
353
|
|
|
|
|
|
|
# }, |
|
354
|
|
|
|
|
|
|
# en { |
|
355
|
|
|
|
|
|
|
# language "en", |
|
356
|
|
|
|
|
|
|
# value "Representation en" |
|
357
|
|
|
|
|
|
|
# } |
|
358
|
|
|
|
|
|
|
# } |
|
359
|
|
|
|
|
|
|
# } |
|
360
|
|
|
|
|
|
|
# ], |
|
361
|
|
|
|
|
|
|
# ns 0, |
|
362
|
|
|
|
|
|
|
# senses [ |
|
363
|
|
|
|
|
|
|
# [0] { |
|
364
|
|
|
|
|
|
|
# claims { |
|
365
|
|
|
|
|
|
|
# P31 [ |
|
366
|
|
|
|
|
|
|
# [0] { |
|
367
|
|
|
|
|
|
|
# mainsnak { |
|
368
|
|
|
|
|
|
|
# datatype "wikibase-item", |
|
369
|
|
|
|
|
|
|
# datavalue { |
|
370
|
|
|
|
|
|
|
# type "wikibase-entityid", |
|
371
|
|
|
|
|
|
|
# value { |
|
372
|
|
|
|
|
|
|
# entity-type "item", |
|
373
|
|
|
|
|
|
|
# id "Q5", |
|
374
|
|
|
|
|
|
|
# numeric-id 5 |
|
375
|
|
|
|
|
|
|
# } |
|
376
|
|
|
|
|
|
|
# }, |
|
377
|
|
|
|
|
|
|
# property "P31", |
|
378
|
|
|
|
|
|
|
# snaktype "value" |
|
379
|
|
|
|
|
|
|
# }, |
|
380
|
|
|
|
|
|
|
# rank "normal", |
|
381
|
|
|
|
|
|
|
# type "statement" |
|
382
|
|
|
|
|
|
|
# } |
|
383
|
|
|
|
|
|
|
# ] |
|
384
|
|
|
|
|
|
|
# }, |
|
385
|
|
|
|
|
|
|
# glosses { |
|
386
|
|
|
|
|
|
|
# cs { |
|
387
|
|
|
|
|
|
|
# language "cs", |
|
388
|
|
|
|
|
|
|
# value "Glosse cs" |
|
389
|
|
|
|
|
|
|
# }, |
|
390
|
|
|
|
|
|
|
# en { |
|
391
|
|
|
|
|
|
|
# language "en", |
|
392
|
|
|
|
|
|
|
# value "Glosse en" |
|
393
|
|
|
|
|
|
|
# } |
|
394
|
|
|
|
|
|
|
# }, |
|
395
|
|
|
|
|
|
|
# id "ID" |
|
396
|
|
|
|
|
|
|
# } |
|
397
|
|
|
|
|
|
|
# ], |
|
398
|
|
|
|
|
|
|
# type "lexeme" |
|
399
|
|
|
|
|
|
|
# } |
|
400
|
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
use strict; |
|
404
|
|
|
|
|
|
|
use warnings; |
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
use Data::Printer; |
|
407
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8); |
|
408
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Lexeme qw(struct2obj); |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
# Lexeme structure. |
|
411
|
|
|
|
|
|
|
my $struct_hr = { |
|
412
|
|
|
|
|
|
|
'claims' => { |
|
413
|
|
|
|
|
|
|
'P5185' => [{ |
|
414
|
|
|
|
|
|
|
'mainsnak' => { |
|
415
|
|
|
|
|
|
|
'datavalue' => { |
|
416
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
|
417
|
|
|
|
|
|
|
'value' => { |
|
418
|
|
|
|
|
|
|
'entity-type' => 'item', |
|
419
|
|
|
|
|
|
|
'id' => 'Q499327', |
|
420
|
|
|
|
|
|
|
'numeric-id' => 499327, |
|
421
|
|
|
|
|
|
|
}, |
|
422
|
|
|
|
|
|
|
}, |
|
423
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
|
424
|
|
|
|
|
|
|
'property' => 'P5185', |
|
425
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
426
|
|
|
|
|
|
|
}, |
|
427
|
|
|
|
|
|
|
'rank' => 'normal', |
|
428
|
|
|
|
|
|
|
'references' => [{ |
|
429
|
|
|
|
|
|
|
'snaks' => { |
|
430
|
|
|
|
|
|
|
'P214' => [{ |
|
431
|
|
|
|
|
|
|
'datavalue' => { |
|
432
|
|
|
|
|
|
|
'type' => 'string', |
|
433
|
|
|
|
|
|
|
'value' => '113230702', |
|
434
|
|
|
|
|
|
|
}, |
|
435
|
|
|
|
|
|
|
'datatype' => 'external-id', |
|
436
|
|
|
|
|
|
|
'property' => 'P214', |
|
437
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
438
|
|
|
|
|
|
|
}], |
|
439
|
|
|
|
|
|
|
'P248' => [{ |
|
440
|
|
|
|
|
|
|
'datavalue' => { |
|
441
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
|
442
|
|
|
|
|
|
|
'value' => { |
|
443
|
|
|
|
|
|
|
'entity-type' => 'item', |
|
444
|
|
|
|
|
|
|
'id' => 'Q53919', |
|
445
|
|
|
|
|
|
|
'numeric-id' => 53919, |
|
446
|
|
|
|
|
|
|
}, |
|
447
|
|
|
|
|
|
|
}, |
|
448
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
|
449
|
|
|
|
|
|
|
'property' => 'P248', |
|
450
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
451
|
|
|
|
|
|
|
}], |
|
452
|
|
|
|
|
|
|
'P813' => [{ |
|
453
|
|
|
|
|
|
|
'datavalue' => { |
|
454
|
|
|
|
|
|
|
'type' => 'time', |
|
455
|
|
|
|
|
|
|
'value' => { |
|
456
|
|
|
|
|
|
|
'after' => 0, |
|
457
|
|
|
|
|
|
|
'before' => 0, |
|
458
|
|
|
|
|
|
|
'calendarmodel' => 'http://test.wikidata.org/entity/Q1985727', |
|
459
|
|
|
|
|
|
|
'precision' => 11, |
|
460
|
|
|
|
|
|
|
'time' => '+2013-12-07T00:00:00Z', |
|
461
|
|
|
|
|
|
|
'timezone' => 0, |
|
462
|
|
|
|
|
|
|
}, |
|
463
|
|
|
|
|
|
|
}, |
|
464
|
|
|
|
|
|
|
'datatype' => 'time', |
|
465
|
|
|
|
|
|
|
'property' => 'P813', |
|
466
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
467
|
|
|
|
|
|
|
}], |
|
468
|
|
|
|
|
|
|
}, |
|
469
|
|
|
|
|
|
|
'snaks-order' => [ |
|
470
|
|
|
|
|
|
|
'P248', |
|
471
|
|
|
|
|
|
|
'P214', |
|
472
|
|
|
|
|
|
|
'P813', |
|
473
|
|
|
|
|
|
|
], |
|
474
|
|
|
|
|
|
|
}], |
|
475
|
|
|
|
|
|
|
'type' => 'statement', |
|
476
|
|
|
|
|
|
|
}], |
|
477
|
|
|
|
|
|
|
}, |
|
478
|
|
|
|
|
|
|
'forms' => [{ |
|
479
|
|
|
|
|
|
|
'claims' => { |
|
480
|
|
|
|
|
|
|
'P898' => [{ |
|
481
|
|
|
|
|
|
|
'mainsnak' => { |
|
482
|
|
|
|
|
|
|
'datavalue' => { |
|
483
|
|
|
|
|
|
|
'type' => 'string', |
|
484
|
|
|
|
|
|
|
'value' => decode_utf8('pɛs'), |
|
485
|
|
|
|
|
|
|
}, |
|
486
|
|
|
|
|
|
|
'datatype' => 'string', |
|
487
|
|
|
|
|
|
|
'property' => 'P898', |
|
488
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
489
|
|
|
|
|
|
|
}, |
|
490
|
|
|
|
|
|
|
'rank' => 'normal', |
|
491
|
|
|
|
|
|
|
'type' => 'statement', |
|
492
|
|
|
|
|
|
|
}], |
|
493
|
|
|
|
|
|
|
}, |
|
494
|
|
|
|
|
|
|
'grammaticalFeatures' => [ |
|
495
|
|
|
|
|
|
|
'Q110786', |
|
496
|
|
|
|
|
|
|
'Q131105', |
|
497
|
|
|
|
|
|
|
], |
|
498
|
|
|
|
|
|
|
'id' => 'L469-F1', |
|
499
|
|
|
|
|
|
|
'representations' => { |
|
500
|
|
|
|
|
|
|
'cs' => { |
|
501
|
|
|
|
|
|
|
'language' => 'cs', |
|
502
|
|
|
|
|
|
|
'value' => 'pes', |
|
503
|
|
|
|
|
|
|
}, |
|
504
|
|
|
|
|
|
|
}, |
|
505
|
|
|
|
|
|
|
}], |
|
506
|
|
|
|
|
|
|
'id' => 'L469', |
|
507
|
|
|
|
|
|
|
'language' => 'Q9056', |
|
508
|
|
|
|
|
|
|
'lastrevid' => 1428556087, |
|
509
|
|
|
|
|
|
|
'lemmas' => { |
|
510
|
|
|
|
|
|
|
'cs' => { |
|
511
|
|
|
|
|
|
|
'language' => 'cs', |
|
512
|
|
|
|
|
|
|
'value' => 'pes', |
|
513
|
|
|
|
|
|
|
}, |
|
514
|
|
|
|
|
|
|
}, |
|
515
|
|
|
|
|
|
|
'lexicalCategory' => 'Q1084', |
|
516
|
|
|
|
|
|
|
'modified' => '2022-06-24T12:42:10Z', |
|
517
|
|
|
|
|
|
|
'ns' => 146, |
|
518
|
|
|
|
|
|
|
'pageid' => 54393954, |
|
519
|
|
|
|
|
|
|
'senses' => [{ |
|
520
|
|
|
|
|
|
|
'claims' => { |
|
521
|
|
|
|
|
|
|
'P18' => [{ |
|
522
|
|
|
|
|
|
|
'mainsnak' => { |
|
523
|
|
|
|
|
|
|
'datavalue' => { |
|
524
|
|
|
|
|
|
|
'type' => 'string', |
|
525
|
|
|
|
|
|
|
'value' => 'Canadian Inuit Dog.jpg', |
|
526
|
|
|
|
|
|
|
}, |
|
527
|
|
|
|
|
|
|
'datatype' => 'commonsMedia', |
|
528
|
|
|
|
|
|
|
'property' => 'P18', |
|
529
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
530
|
|
|
|
|
|
|
}, |
|
531
|
|
|
|
|
|
|
'rank' => 'normal', |
|
532
|
|
|
|
|
|
|
'type' => 'statement', |
|
533
|
|
|
|
|
|
|
}], |
|
534
|
|
|
|
|
|
|
'P5137' => [{ |
|
535
|
|
|
|
|
|
|
'mainsnak' => { |
|
536
|
|
|
|
|
|
|
'datavalue' => { |
|
537
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
|
538
|
|
|
|
|
|
|
'value' => { |
|
539
|
|
|
|
|
|
|
'entity-type' => 'item', |
|
540
|
|
|
|
|
|
|
'id' => 'Q144', |
|
541
|
|
|
|
|
|
|
'numeric-id' => 144, |
|
542
|
|
|
|
|
|
|
}, |
|
543
|
|
|
|
|
|
|
}, |
|
544
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
|
545
|
|
|
|
|
|
|
'property' => 'P5137', |
|
546
|
|
|
|
|
|
|
'snaktype' => 'value', |
|
547
|
|
|
|
|
|
|
}, |
|
548
|
|
|
|
|
|
|
'rank' => 'normal', |
|
549
|
|
|
|
|
|
|
'type' => 'statement', |
|
550
|
|
|
|
|
|
|
}], |
|
551
|
|
|
|
|
|
|
}, |
|
552
|
|
|
|
|
|
|
'glosses' => { |
|
553
|
|
|
|
|
|
|
'cs' => { |
|
554
|
|
|
|
|
|
|
'language' => 'cs', |
|
555
|
|
|
|
|
|
|
'value' => decode_utf8('psovitá šelma chovaná jako domácí zvíře'), |
|
556
|
|
|
|
|
|
|
}, |
|
557
|
|
|
|
|
|
|
'en' => { |
|
558
|
|
|
|
|
|
|
'language' => 'en', |
|
559
|
|
|
|
|
|
|
'value' => 'domesticated mammal related to the wolf', |
|
560
|
|
|
|
|
|
|
}, |
|
561
|
|
|
|
|
|
|
}, |
|
562
|
|
|
|
|
|
|
'id' => 'L469-S1', |
|
563
|
|
|
|
|
|
|
}], |
|
564
|
|
|
|
|
|
|
'title' => 'Lexeme:L469', |
|
565
|
|
|
|
|
|
|
'type' => 'lexeme', |
|
566
|
|
|
|
|
|
|
}; |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# Get object. |
|
569
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
# Dump object. |
|
572
|
|
|
|
|
|
|
p $obj; |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
# Output: |
|
575
|
|
|
|
|
|
|
# Wikibase::Datatype::Lexeme { |
|
576
|
|
|
|
|
|
|
# parents: Mo::Object |
|
577
|
|
|
|
|
|
|
# public methods (5): |
|
578
|
|
|
|
|
|
|
# BUILD |
|
579
|
|
|
|
|
|
|
# Error::Pure: |
|
580
|
|
|
|
|
|
|
# err |
|
581
|
|
|
|
|
|
|
# Mo::utils: |
|
582
|
|
|
|
|
|
|
# check_array_object, check_number |
|
583
|
|
|
|
|
|
|
# Wikibase::Datatype::Utils: |
|
584
|
|
|
|
|
|
|
# check_entity |
|
585
|
|
|
|
|
|
|
# private methods (0) |
|
586
|
|
|
|
|
|
|
# internals: { |
|
587
|
|
|
|
|
|
|
# forms [ |
|
588
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Form |
|
589
|
|
|
|
|
|
|
# ], |
|
590
|
|
|
|
|
|
|
# id "L469", |
|
591
|
|
|
|
|
|
|
# language "Q9056", |
|
592
|
|
|
|
|
|
|
# lastrevid 1428556087, |
|
593
|
|
|
|
|
|
|
# lemmas [ |
|
594
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Value::Monolingual |
|
595
|
|
|
|
|
|
|
# ], |
|
596
|
|
|
|
|
|
|
# lexical_category "Q1084", |
|
597
|
|
|
|
|
|
|
# modified "2022-06-24T12:42:10Z" (dualvar: 2022), |
|
598
|
|
|
|
|
|
|
# ns 146, |
|
599
|
|
|
|
|
|
|
# page_id 54393954, |
|
600
|
|
|
|
|
|
|
# senses [ |
|
601
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Sense |
|
602
|
|
|
|
|
|
|
# ], |
|
603
|
|
|
|
|
|
|
# statements [ |
|
604
|
|
|
|
|
|
|
# [0] Wikibase::Datatype::Statement |
|
605
|
|
|
|
|
|
|
# ], |
|
606
|
|
|
|
|
|
|
# title "Lexeme:L469" |
|
607
|
|
|
|
|
|
|
# } |
|
608
|
|
|
|
|
|
|
# } |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
L<Error::Pure>, |
|
613
|
|
|
|
|
|
|
L<Exporter>, |
|
614
|
|
|
|
|
|
|
L<Readonly>, |
|
615
|
|
|
|
|
|
|
L<Wikibase::Datatype::Form>, |
|
616
|
|
|
|
|
|
|
L<Wikibase::Datatype::Lexeme>, |
|
617
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Form>, |
|
618
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Language>, |
|
619
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Sense>, |
|
620
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Statement>, |
|
621
|
|
|
|
|
|
|
L<Wikibase::Datatype::Value::Item>. |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
624
|
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=over |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Form> |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
Wikibase form datatype. |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Sense> |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
Wikibase sense datatype. |
|
634
|
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
Wikibase structure serialization. |
|
638
|
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
=back |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
642
|
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=head1 AUTHOR |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
|
648
|
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
L<http://skim.cz> |
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
© 2020-2022 Michal Josef Špaček |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
BSD 2-Clause License |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=head1 VERSION |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
0.09 |
|
660
|
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
=cut |