Wikidata/Item.pm

filter: Statementstmt 30.0% 108 / 359 Branchbran 6.1% 8 / 130 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 44.0% 26 / 59 Podpod 0.0% 0 / 32 totaltotal 23.8% 143 / 599 CC 86 SCAR 36.3
CC
86
Cov
23%
wikidata_place_of_publication
132.0
wikidata_isbn_10
110.0
wikidata_isbn_13
110.0
CRAP 37.9
↑ Summary Wikidata/Item/BookEdition.pm »
1 package MARC::Convert::Wikidata::Item;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use MARC::Convert::Wikidata::Utils qw(look_for_external_id);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use Mo::utils 0.08 qw(check_isa check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use Unicode::UTF8 qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use Wikibase::Datatype::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use Wikibase::Datatype::Snak;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use Wikibase::Datatype::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 21 ▶use Wikibase::Datatype::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 21 ▶use Wikibase::Datatype::Value::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 ▶use Wikibase::Datatype::Value::Monolingual;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 21 ▶use Wikibase::Datatype::Value::Quantity;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 21 ▶use Wikibase::Datatype::Value::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 21 ▶use Wikibase::Datatype::Value::Time;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 21 Readonly::Hash our %EXT_ID_MAPPING => (
26 'cnb' => 'P3184',
27 'lccn' => 'P243',
28 );
29  
30 21 our $VERSION = 0.34;
31  
32 # Constructor.
33 18 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
34 18 my ($class, @params) = @_;
35  
36 # Create object.
37 18 my $self = bless {}, $class;
38  
39 # Cover callback.
40 18 $self->{'callback_cover'} = undef;
41  
42 # Cycles callback.
43 18 $self->{'callback_cycles'} = undef;
44  
45 # Lang callback.
46 18 $self->{'callback_lang'} = undef;
47  
48 # People callback.
49 18 $self->{'callback_people'} = undef;
50  
51 # Place of publication Wikidata lookup callback.
52 18 $self->{'callback_publisher_place'} = undef;
53  
54 # Publisher Wikidata lookup callback.
55 18 $self->{'callback_publisher_name'} = undef;
56  
57 # Book series Wikidata lookup callback.
58 18 $self->{'callback_series'} = undef;
59  
60 # Retrieved date.
61 18 $self->{'date_retrieved'} = undef;
62  
63 # MARC::Record object.
64 18 $self->{'marc_record'} = undef;
65  
66 # Transform object.
67 18 $self->{'transform_object'} = undef;
68  
69 # Process parameters.
70 18 set_params($self, @params);
71  
72 18 check_required($self, 'marc_record');
73 14 check_isa($self, 'marc_record', 'MARC::Record');
74  
75 10 ▶ if (! defined $self->{'date_retrieved'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"date_retrieved"}) 10 0 10
76 10 $self->{'date_retrieved'} = '+'.DateTime->now
77 ->truncate('to' => 'day')->iso8601().'Z';
78 }
79  
80 10 return $self;
81 }
82  
83 1 ▶sub wikidata_authors {
Subroutine wikidata_authors: called CC=1 SCAR=0.0
Pod undocumented
84 1 my $self = shift;
85  
86 1 return $self->wikidata_people('authors', 'P50');
87 }
88  
89 0 ▶sub wikidata_authors_of_afterword {
Subroutine wikidata_authors_of_afterword: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $self = shift;
91  
92 0 return $self->wikidata_people('authors_of_afterword', 'P2680');
93 }
94  
95 0 ▶sub wikidata_authors_of_introduction {
Subroutine wikidata_authors_of_introduction: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my $self = shift;
97  
98 0 return $self->wikidata_people('authors_of_introduction', 'P2679');
99 }
100  
101 0 ▶sub wikidata_compilers {
Subroutine wikidata_compilers: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my $self = shift;
103  
104 0 my $property_snaks_ar = [
105 Wikibase::Datatype::Snak->new(
106 'datatype' => 'wikibase-item',
107 'datavalue' => Wikibase::Datatype::Value::Item->new(
108 'value' => 'Q29514511',
109 ),
110 'property' => 'P3831',
111 ),
112 ];
113 0 return $self->wikidata_people('compilers', 'P98', $property_snaks_ar);
114 }
115  
116 4 ▶sub wikidata_descriptions {
Subroutine wikidata_descriptions: called CC=2 SCAR=7.6
Pod undocumented
117 4 my $self = shift;
118  
119 4 ▶ if (! defined $self->{'transform_object'}->full_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->full_name) 0 4 4
120 0 return ();
121 }
122  
123 return (
124 4 'descriptions' => [
125 Wikibase::Datatype::Term->new(
126 'language' => 'cs',
127 'value' => $self->_description('cs'),
128 ),
129 Wikibase::Datatype::Term->new(
130 'language' => 'en',
131 'value' => $self->_description('en'),
132 ),
133 ],
134 );
135 }
136  
137 0 ▶sub wikidata_directors {
Subroutine wikidata_directors: not called CC=1 SCAR=6.9
Pod undocumented
138 0 my $self = shift;
139  
140 0 return $self->wikidata_people('directors', 'P57');
141 }
142  
143 0 ▶sub wikidata_dml {
Subroutine wikidata_dml: not called CC=2 SCAR=17.9
Pod undocumented
144 0 my $self = shift;
145  
146 0 ▶ if (! defined $self->{'transform_object'}->dml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->dml) 0 0 0
147 0 return;
148 }
149  
150 return Wikibase::Datatype::Statement->new(
151 'references' => [$self->wikidata_reference],
152 'snak' => Wikibase::Datatype::Snak->new(
153 'datatype' => 'external-id',
154 'datavalue' => Wikibase::Datatype::Value::String->new(
155 0 'value' => $self->{'transform_object'}->dml,
156 ),
157 'property' => 'P11378',
158 ),
159 );
160 }
161  
162 0 ▶sub wikidata_edition_number {
Subroutine wikidata_edition_number: not called CC=2 SCAR=17.9
Pod undocumented
163 0 my $self = shift;
164  
165 0 ▶ if (! defined $self->{'transform_object'}->edition_number) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->edition_number) 0 0 0
166 0 return;
167 }
168  
169 return (
170 Wikibase::Datatype::Statement->new(
171 'references' => [$self->wikidata_reference],
172 'snak' => Wikibase::Datatype::Snak->new(
173 'datatype' => 'string',
174 'datavalue' => Wikibase::Datatype::Value::String->new(
175 0 'value' => $self->{'transform_object'}->edition_number,
176 ),
177 'property' => 'P393',
178 ),
179 ),
180 );
181 }
182  
183 0 ▶sub wikidata_editors {
Subroutine wikidata_editors: not called CC=1 SCAR=6.9
Pod undocumented
184 0 my $self = shift;
185  
186 0 return $self->wikidata_people('editors', 'P98');
187 }
188  
189 1 ▶sub wikidata_end_time {
Subroutine wikidata_end_time: called CC=3 SCAR=14.2
Pod undocumented
190 1 my $self = shift;
191  
192 1 ▶ if (! defined $self->{'transform_object'}->end_time
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"transform_object"}->end_time or $self->{"transform_object"}->end_time eq 9999) 1 0 1
Condition33%1/3
not defined $self->{"transform_object"}->end_time or $self->{"transform_object"}->end_time eq 9999
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $self->{"transform_object"}->end_time or $self->{"transform_object"}->end_time eq 9999
not defined $self->{"transform_object"}->end_time $self->{"transform_object"}->end_time eq 9999
Truth table33%1/3
not(A) or B
A= not defined $self->{"transform_object"}->end_timeB= $self->{"transform_object"}->end_time eq 9999
ABresult
1X1
011
000
193  
194 # Unfinished periodical.
195 || $self->{'transform_object'}->end_time eq '9999') {
196  
197 1 return;
198 }
199  
200 # XXX end_time is every year? Probably not.
201 0 my $end_time = $self->{'transform_object'}->end_time;
202  
203 0 return $self->_year($end_time, 'end time', 'P582');
204 }
205  
206 0 ▶sub wikidata_external_ids {
Subroutine wikidata_external_ids: not called CC=4 SCAR=30.0
Pod undocumented
207 0 my $self = shift;
208  
209 0 my @ret;
210 0 foreach my $external_id (@{$self->{'transform_object'}->external_ids}) {
211 push @ret, Wikibase::Datatype::Statement->new(
212 $external_id->deprecated ? (
213 'rank' => 'deprecated',
214 ) : (),
215 'references' => [$self->wikidata_reference],
216 'snak' => Wikibase::Datatype::Snak->new(
217 'datatype' => 'external-id',
218 'datavalue' => Wikibase::Datatype::Value::String->new(
219 'value' => $external_id->value,
220 ),
221 0 ▶ 'property' => $EXT_ID_MAPPING{$external_id->name},
Branch: 2 branches
BranchTrueFalseTotal
$external_id->deprecated ? : 0 0 0
$external_id->deprecated ? : 0 0 0
222 ),
223 $external_id->deprecated ? (
224 'property_snaks' => [
225 Wikibase::Datatype::Snak->new(
226 'datatype' => 'wikibase-item',
227 'datavalue' => Wikibase::Datatype::Value::Item->new(
228 'value' => 'Q21441764',
229 ),
230 'property' => 'P2241',
231 ),
232 ],
233 ) : (),
234 ),
235 }
236  
237 0 return @ret;
238 }
239  
240 0 ▶sub wikidata_illustrators {
Subroutine wikidata_illustrators: not called CC=1 SCAR=6.9
Pod undocumented
241 0 my $self = shift;
242  
243 0 return $self->wikidata_people('illustrators', 'P110');
244 }
245  
246 0 ▶sub wikidata_isbn_10 {
Subroutine wikidata_isbn_10: not called CC=10 SCAR=47.0
Pod undocumented
247 0 my $self = shift;
248  
249 0 ▶ if (! @{$self->{'transform_object'}->isbns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->isbns;}) 0 0 0
250 0 return;
251 }
252  
253 0 my @ret;
254 0 foreach my $isbn (@{$self->{'transform_object'}->isbns}) {
255 0 ▶ if ($isbn->type != 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->type != 10) 0 0 0
256 0 next;
257 }
258  
259 # Skip collective ISBNs.
260 0 ▶ if ($isbn->collective) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->collective) 0 0 0
261 0 next;
262 }
263  
264 0 my $publisher = $self->_isbn_publisher($isbn);
265 0 my $cover_qid = $self->_isbn_cover($isbn);
266 0 my @property_snaks;
267 0 ▶ if ($isbn->valid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->valid == 0) 0 0 0
268 0 push @property_snaks, Wikibase::Datatype::Snak->new(
269 'datatype' => 'wikibase-item',
270 'datavalue' => Wikibase::Datatype::Value::Item->new(
271 'value' => 'Q21441764',
272 ),
273 'property' => 'P2241',
274 );
275 }
276 0 ▶ if (defined $publisher) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $publisher) 0 0 0
277 0 push @property_snaks, Wikibase::Datatype::Snak->new(
278 'datatype' => 'wikibase-item',
279 'datavalue' => Wikibase::Datatype::Value::Item->new(
280 'value' => $publisher->[0],
281 ),
282 'property' => 'P123',
283 );
284 }
285 0 ▶ if (defined $cover_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cover_qid) 0 0 0
286 0 push @property_snaks, Wikibase::Datatype::Snak->new(
287 'datatype' => 'wikibase-item',
288 'datavalue' => Wikibase::Datatype::Value::Item->new(
289 'value' => $cover_qid,
290 ),
291 'property' => 'P437',
292 );
293 }
294 0 ▶ push @ret, Wikibase::Datatype::Statement->new(
Branch: 2 branches
BranchTrueFalseTotal
$isbn->valid == 0 ? : 0 0 0
@property_snaks ? : 0 0 0
295 $isbn->valid == 0 ? (
296 'rank' => 'deprecated',
297 ) : (),
298 'references' => [$self->wikidata_reference],
299 'snak' => Wikibase::Datatype::Snak->new(
300 'datatype' => 'external-id',
301 'datavalue' => Wikibase::Datatype::Value::String->new(
302 'value' => $isbn->isbn,
303 ),
304 'property' => 'P957',
305 ),
306 @property_snaks ? (
307 'property_snaks' => \@property_snaks,
308 ) : (),
309 );
310 }
311  
312 0 return @ret;
313 }
314  
315 0 ▶sub wikidata_isbn_13 {
Subroutine wikidata_isbn_13: not called CC=10 SCAR=47.0
Pod undocumented
316 0 my $self = shift;
317  
318 0 ▶ if (! @{$self->{'transform_object'}->isbns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->isbns;}) 0 0 0
319 0 return;
320 }
321  
322 0 my @ret;
323 0 foreach my $isbn (@{$self->{'transform_object'}->isbns}) {
324 0 ▶ if ($isbn->type != 13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->type != 13) 0 0 0
325 0 next;
326 }
327  
328 # Skip collective ISBNs.
329 0 ▶ if ($isbn->collective) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->collective) 0 0 0
330 0 next;
331 }
332  
333 0 my $publisher = $self->_isbn_publisher($isbn);
334 0 my $cover_qid = $self->_isbn_cover($isbn);
335 0 my @property_snaks;
336 0 ▶ if ($isbn->valid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isbn->valid == 0) 0 0 0
337 0 push @property_snaks, Wikibase::Datatype::Snak->new(
338 'datatype' => 'wikibase-item',
339 'datavalue' => Wikibase::Datatype::Value::Item->new(
340 'value' => 'Q21441764',
341 ),
342 'property' => 'P2241',
343 );
344 }
345 0 ▶ if (defined $publisher) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $publisher) 0 0 0
346 0 push @property_snaks, Wikibase::Datatype::Snak->new(
347 'datatype' => 'wikibase-item',
348 'datavalue' => Wikibase::Datatype::Value::Item->new(
349 'value' => $publisher->[0],
350 ),
351 'property' => 'P123',
352 );
353 }
354 0 ▶ if (defined $cover_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cover_qid) 0 0 0
355 0 push @property_snaks, Wikibase::Datatype::Snak->new(
356 'datatype' => 'wikibase-item',
357 'datavalue' => Wikibase::Datatype::Value::Item->new(
358 'value' => $cover_qid,
359 ),
360 'property' => 'P437',
361 );
362 }
363 0 ▶ push @ret, Wikibase::Datatype::Statement->new(
Branch: 2 branches
BranchTrueFalseTotal
$isbn->valid == 0 ? : 0 0 0
@property_snaks ? : 0 0 0
364 $isbn->valid == 0 ? (
365 'rank' => 'deprecated',
366 ) : (),
367 'references' => [$self->wikidata_reference],
368 'snak' => Wikibase::Datatype::Snak->new(
369 'datatype' => 'external-id',
370 'datavalue' => Wikibase::Datatype::Value::String->new(
371 'value' => $isbn->isbn,
372 ),
373 'property' => 'P212',
374 ),
375 @property_snaks ? (
376 'property_snaks' => \@property_snaks,
377 ) : (),
378 );
379 }
380  
381 0 return @ret;
382 }
383  
384 0 ▶sub wikidata_issn {
Subroutine wikidata_issn: not called CC=2 SCAR=17.9
Pod undocumented
385 0 my $self = shift;
386  
387 0 ▶ if (! $self->{'transform_object'}->issn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"transform_object"}->issn) 0 0 0
388 0 return;
389 }
390  
391 return (
392 Wikibase::Datatype::Statement->new(
393 'references' => [$self->wikidata_reference],
394 'snak' => Wikibase::Datatype::Snak->new(
395 'datatype' => 'external-id',
396 'datavalue' => Wikibase::Datatype::Value::String->new(
397 0 'value' => $self->{'transform_object'}->issn,
398 ),
399 'property' => 'P236',
400 ),
401 ),
402 );
403 }
404  
405 0 ▶sub wikidata_labels {
Subroutine wikidata_labels: not called CC=2 SCAR=17.9
Pod undocumented
406 0 my $self = shift;
407  
408 0 ▶ if (! defined $self->{'transform_object'}->full_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->full_name) 0 0 0
409 0 return ();
410 }
411  
412 return (
413 'labels' => [
414 Wikibase::Datatype::Term->new(
415 'language' => 'mul',
416 0 'value' => $self->{'transform_object'}->full_name,
417 ),
418 ],
419 );
420 }
421  
422 0 ▶sub wikidata_language {
Subroutine wikidata_language: not called CC=6 SCAR=37.4
Pod undocumented
423 0 my $self = shift;
424  
425 0 ▶ if (! @{$self->{'transform_object'}->languages}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->languages;}) 0 0 0
426 0 return;
427 }
428  
429 0 ▶ if (! defined $self->{'callback_lang'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"callback_lang"}) 0 0 0
430 0 warn "No callback method for translation of language.\n";
431 0 return;
432 }
433  
434 0 my @language_qids;
435 0 foreach my $lang (@{$self->{'transform_object'}->languages}) {
436 0 my $language_qid = $self->{'callback_lang'}->($lang);
437 0 ▶ if (defined $language_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $language_qid) 0 0 0
438 0 push @language_qids, $language_qid;
439 }
440 }
441  
442 0 my @lang;
443 0 foreach my $language_qid (@language_qids) {
444 0 push @lang, Wikibase::Datatype::Statement->new(
445 'references' => [$self->wikidata_reference],
446 'snak' => Wikibase::Datatype::Snak->new(
447 'datatype' => 'wikibase-item',
448 'datavalue' => Wikibase::Datatype::Value::Item->new(
449 'value' => $language_qid,
450 ),
451 'property' => 'P407',
452 ),
453 );
454 }
455  
456 0 return @lang;
457 }
458  
459 0 ▶sub wikidata_krameriuses {
Subroutine wikidata_krameriuses: not called CC=6 SCAR=37.4
Pod undocumented
460 0 my $self = shift;
461  
462 0 ▶ if (! defined $self->{'transform_object'}->krameriuses) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->krameriuses) 0 0 0
463 0 return;
464 }
465  
466 0 my @krameriuses;
467 0 foreach my $k (@{$self->{'transform_object'}->krameriuses}) {
468  
469 # Rewriting to Czech Digital Library
470 0 ▶ if ($k->kramerius_id eq 'mzk' || $k->kramerius_id eq 'nkp'
Branch: 1 branch
BranchTrueFalseTotal
if ($k->kramerius_id eq 'mzk' or $k->kramerius_id eq 'nkp' or $k->kramerius_id eq 'ndk') { } 0 0 0
Condition0%0/6
$k->kramerius_id eq "mzk" or $k->kramerius_id eq "nkp" or $k->kramerius_id eq "ndk"
l!l&&r!l&&!r
000
$k->kramerius_id eq "mzk" or $k->kramerius_id eq "nkp"
l!l&&r!l&&!r
000
MC/DC0%0/3
$k->kramerius_id eq "mzk" or $k->kramerius_id eq "nkp" or $k->kramerius_id eq "ndk"
$k->kramerius_id eq "mzk" $k->kramerius_id eq "nkp" $k->kramerius_id eq "ndk"
Truth table0%0/4
A or B or C
A= $k->kramerius_id eq "mzk"B= $k->kramerius_id eq "nkp"C= $k->kramerius_id eq "ndk"
ABCresult
1XX1
01X1
0011
0000
471 || $k->kramerius_id eq 'ndk') {
472  
473 0 push @krameriuses, Wikibase::Datatype::Statement->new(
474 'references' => [$self->wikidata_reference],
475 'snak' => Wikibase::Datatype::Snak->new(
476 'datatype' => 'external-id',
477 'datavalue' => Wikibase::Datatype::Value::String->new(
478 'value' => $k->object_id,
479 ),
480 'property' => 'P13032',
481 ),
482 ),
483 } else {
484 0 push @krameriuses, Wikibase::Datatype::Statement->new(
485 'references' => [$self->wikidata_reference],
486 'snak' => Wikibase::Datatype::Snak->new(
487 'datatype' => 'url',
488 'datavalue' => Wikibase::Datatype::Value::String->new(
489 'value' => $k->url,
490 ),
491 'property' => 'P953',
492 ),
493 # TODO Language of work or name: Czech
494 ),
495 }
496 }
497  
498 0 return @krameriuses;
499 }
500  
501 0 ▶sub wikidata_narrators {
Subroutine wikidata_narrators: not called CC=1 SCAR=6.9
Pod undocumented
502 0 my $self = shift;
503  
504 0 return $self->wikidata_people('narrators', 'P2438');
505 }
506  
507 0 ▶sub wikidata_number_of_pages {
Subroutine wikidata_number_of_pages: not called CC=2 SCAR=17.9
Pod undocumented
508 0 my $self = shift;
509  
510 0 ▶ if (! defined $self->{'transform_object'}->number_of_pages) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->number_of_pages) 0 0 0
511 0 return;
512 }
513  
514 return (
515 Wikibase::Datatype::Statement->new(
516 'references' => [$self->wikidata_reference],
517 'snak' => Wikibase::Datatype::Snak->new(
518 'datatype' => 'quantity',
519 'datavalue' => Wikibase::Datatype::Value::Quantity->new(
520 'unit' => 'Q1069725',
521 0 'value' => $self->{'transform_object'}->number_of_pages,
522 ),
523 'property' => 'P1104',
524 ),
525 ),
526 );
527 }
528  
529 1 ▶sub wikidata_people {
Subroutine wikidata_people: called CC=10 SCAR=28.7
Pod undocumented
530 1 my ($self, $people_method, $people_property, $property_snaks_ar) = @_;
531  
532 1 ▶ if (! @{$self->{'transform_object'}->$people_method}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->$people_method;}) 0 1 1
533 0 return;
534 }
535  
536 1 ▶ if (! defined $self->{'callback_people'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"callback_people"}) 0 1 1
537 0 warn "No callback method for translation of people in '$people_method' method.\n";
538 0 return;
539 }
540  
541 1 my @people_qids;
542 my @people_strings;
543 1 foreach my $people (@{$self->{'transform_object'}->$people_method}) {
544 3 my $people_qid = $self->{'callback_people'}->($people);
545 3 ▶ if (defined $people_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $people_qid) { } 0 3 3
546 # -1 is error, not process
547 0 ▶ if ($people_qid ne '-1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($people_qid ne -1) 0 0 0
548 0 push @people_qids, $people_qid;
549 }
550 } else {
551 3 push @people_strings, $people->name.' '.$people->surname;
552 }
553 }
554  
555 1 my @people;
556 1 foreach my $people_qid (@people_qids) {
557 0 ▶ push @people, Wikibase::Datatype::Statement->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $property_snaks_ar ? : 0 0 0
558 defined $property_snaks_ar ? (
559 'property_snaks' => $property_snaks_ar,
560 ) : (),
561 'references' => [$self->wikidata_reference],
562 'snak' => Wikibase::Datatype::Snak->new(
563 'datatype' => 'wikibase-item',
564 'datavalue' => Wikibase::Datatype::Value::Item->new(
565 'value' => $people_qid,
566 ),
567 'property' => $people_property,
568 ),
569 ),
570 }
571  
572 1 foreach my $people_string (@people_strings) {
573 3 ▶ push @people, Wikibase::Datatype::Statement->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $property_snaks_ar ? : 0 3 3
574 defined $property_snaks_ar ? (
575 'property_snaks' => $property_snaks_ar,
576 ) : (),
577 'references' => [$self->wikidata_reference],
578 'snak' => Wikibase::Datatype::Snak->new(
579 'datatype' => 'string',
580 'datavalue' => Wikibase::Datatype::Value::String->new(
581 'value' => $people_string,
582 ),
583 'property' => 'P2093',
584 ),
585 );
586 }
587  
588 1 return @people;
589 }
590  
591 0 ▶sub wikidata_photographers {
Subroutine wikidata_photographers: not called CC=1 SCAR=6.9
Pod undocumented
592 0 my $self = shift;
593  
594 0 my $property_snaks_ar = [
595 Wikibase::Datatype::Snak->new(
596 'datatype' => 'wikibase-item',
597 'datavalue' => Wikibase::Datatype::Value::Item->new(
598 'value' => 'Q33231',
599 ),
600 'property' => 'P3831',
601 ),
602 ];
603 0 return $self->wikidata_people('photographers', 'P50', $property_snaks_ar);
604 }
605  
606 0 ▶sub wikidata_place_of_publication {
Subroutine wikidata_place_of_publication: not called CC=11 SCAR=48.8
Pod undocumented
607 0 my $self = shift;
608  
609 0 ▶ if (! @{$self->{'transform_object'}->publishers}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->publishers;}) 0 0 0
610 0 return;
611 }
612  
613 0 my @places;
614 0 my $publication_date = $self->{'transform_object'}->publication_date;
615 0 ▶ if (! defined $self->{'callback_publisher_place'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'callback_publisher_place'}) { } 0 0 0
616 0 return;
617 } else {
618 0 foreach my $publisher (@{$self->{'transform_object'}->publishers}) {
619 0 my $place_qid;
620 # No concrete place.
621 0 ▶ if ($publisher->place eq 'sine loco') {
Branch: 1 branch
BranchTrueFalseTotal
if ($publisher->place eq 'sine loco') { } 0 0 0
622 0 $place_qid = 'Q11254169';
623 } else {
624 0 $place_qid = $self->{'callback_publisher_place'}->($publisher);
625 }
626 0 my $publisher_qid = $self->{'callback_publisher_name'}->($publisher, $publication_date);
627 0 ▶ if (defined $publisher_qid && $place_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $publisher_qid and $place_qid) 0 0 0
Condition0%0/3
defined $publisher_qid and $place_qid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publisher_qid and $place_qid
defined $publisher_qid $place_qid
Truth table0%0/3
A and B
A= defined $publisher_qidB= $place_qid
ABresult
0X0
100
111
628 0 push @places, [$publisher_qid, $place_qid];
629 }
630 }
631 }
632  
633 0 ▶ if (! @places) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@places) 0 0 0
634 0 return;
635 }
636  
637 0 ▶ my $multiple = @places > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@places > 1 ? : 0 0 0
638 0 my @ret;
639 0 foreach my $place (@places) {
640 0 ▶ push @ret, Wikibase::Datatype::Statement->new(
Branch: 1 branch
BranchTrueFalseTotal
$multiple ? : 0 0 0
641 'references' => [$self->wikidata_reference],
642 'snak' => Wikibase::Datatype::Snak->new(
643 'datatype' => 'wikibase-item',
644 'datavalue' => Wikibase::Datatype::Value::Item->new(
645 'value' => $place->[1],
646 ),
647 'property' => 'P291',
648 ),
649 $multiple ? (
650 'property_snaks' => [
651 Wikibase::Datatype::Snak->new(
652 'datatype' => 'wikibase-item',
653 'datavalue' => Wikibase::Datatype::Value::Item->new(
654 'value' => $place->[0],
655 ),
656 'property' => 'P123',
657 ),
658 ],
659 ) : (),
660 );
661 }
662  
663 0 return @ret;
664 }
665  
666 0 ▶sub wikidata_publication_date {
Subroutine wikidata_publication_date: not called CC=2 SCAR=17.9
Pod undocumented
667 0 my $self = shift;
668  
669 0 ▶ if (! defined $self->{'transform_object'}->publication_date) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->publication_date) 0 0 0
670 0 return;
671 }
672  
673 # TODO Second parameter of publication_date().
674  
675 # XXX Publication date is every year? Probably not.
676 0 my $publication_date = $self->{'transform_object'}->publication_date;
677  
678 0 return $self->_year($publication_date, 'publication date', 'P577');
679 }
680  
681 0 ▶sub wikidata_publishers {
Subroutine wikidata_publishers: not called CC=4 SCAR=30.0
Pod undocumented
682 0 my $self = shift;
683  
684 0 ▶ if (! @{$self->{'transform_object'}->publishers}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->publishers;}) 0 0 0
685 0 return;
686 }
687  
688 0 my @publisher_qids = $self->_publisher_translate(@{$self->{'transform_object'}->publishers});
689 0 ▶ if (! @publisher_qids) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@publisher_qids) 0 0 0
690 0 return;
691 }
692  
693 0 my @publishers;
694 0 foreach my $publisher_ar (@publisher_qids) {
695 0 push @publishers, Wikibase::Datatype::Statement->new(
696 'references' => [$self->wikidata_reference],
697 'snak' => Wikibase::Datatype::Snak->new(
698 'datatype' => 'wikibase-item',
699 'datavalue' => Wikibase::Datatype::Value::Item->new(
700 'value' => $publisher_ar->[0],
701 ),
702 'property' => 'P123',
703 ),
704 'property_snaks' => [
705 Wikibase::Datatype::Snak->new(
706 'datatype' => 'string',
707 'datavalue' => Wikibase::Datatype::Value::String->new(
708 'value' => $publisher_ar->[1],
709 ),
710 'property' => 'P1810',
711 ),
712 ],
713 );
714 }
715  
716 0 return @publishers;
717 }
718  
719 3 ▶sub wikidata_reference {
Subroutine wikidata_reference: called CC=2 SCAR=7.4
Pod undocumented
720 3 my $self = shift;
721  
722 3 my $ccnb = look_for_external_id($self->{'transform_object'}, 'cnb');
723 3 ▶ if (! defined $ccnb) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ccnb) 0 3 3
724 0 err decode_utf8('Missing ČČNB id.');
725 }
726 return (
727 Wikibase::Datatype::Reference->new(
728 'snaks' => [
729 # Stated in Czech National Bibliography
730 Wikibase::Datatype::Snak->new(
731 'datatype' => 'wikibase-item',
732 'datavalue' => Wikibase::Datatype::Value::Item->new(
733 'value' => 'Q86914821',
734 ),
735 'property' => 'P248',
736 ),
737  
738 # Czech National Bibliography book ID
739 Wikibase::Datatype::Snak->new(
740 'datatype' => 'external-id',
741 'datavalue' => Wikibase::Datatype::Value::String->new(
742 'value' => $ccnb,
743 ),
744 'property' => 'P3184',
745 ),
746  
747 # Retrieved.
748 Wikibase::Datatype::Snak->new(
749 'datatype' => 'time',
750 'datavalue' => Wikibase::Datatype::Value::Time->new(
751 3 'value' => $self->{'date_retrieved'},
752 ),
753 'property' => 'P813',
754 ),
755 ],
756 ),
757 );
758 }
759  
760 0 ▶sub wikidata_series {
Subroutine wikidata_series: not called CC=8 SCAR=42.8
Pod undocumented
761 0 my $self = shift;
762  
763 0 ▶ if (! @{$self->{'transform_object'}->series}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->series;}) 0 0 0
764 0 return;
765 }
766  
767 0 my @series_qids;
768 0 ▶ if (! defined $self->{'callback_series'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'callback_series'}) { } 0 0 0
769 0 return;
770 } else {
771 # No warn flag for use case when we found series.
772 0 my $found = 0;
773 0 foreach my $series (
774 0 @{$self->{'transform_object'}->series},
775 0 @{$self->{'transform_object'}->cycles}
776 ) {
777  
778 0 my $series_qid = $self->{'callback_series'}->($series, $found);
779 0 ▶ if ($series_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($series_qid) 0 0 0
780 0 push @series_qids, [
781 $series_qid,
782 $series->name,
783 $series->series_ordinal,
784 ];
785 0 $found = 1;
786 }
787 }
788 }
789  
790 0 ▶ if (! @series_qids) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@series_qids) 0 0 0
791 0 return;
792 }
793  
794 0 my @series;
795 0 foreach my $series_ar (@series_qids) {
796 0 ▶ push @series, Wikibase::Datatype::Statement->new(
Branch: 1 branch
BranchTrueFalseTotal
$series_ar->[2] ? : 0 0 0
797 'references' => [$self->wikidata_reference],
798 'snak' => Wikibase::Datatype::Snak->new(
799 'datatype' => 'wikibase-item',
800 'datavalue' => Wikibase::Datatype::Value::Item->new(
801 'value' => $series_ar->[0],
802 ),
803 'property' => 'P179',
804 ),
805 'property_snaks' => [
806  
807 # Series ordinal.
808 $series_ar->[2] ? (
809 Wikibase::Datatype::Snak->new(
810 'datatype' => 'string',
811 'datavalue' => Wikibase::Datatype::Value::String->new(
812 'value' => $series_ar->[2],
813 ),
814 'property' => 'P1545',
815 ),
816 ) : (),
817 ],
818 );
819 }
820  
821 0 return @series;
822 }
823  
824 0 ▶sub wikidata_start_time {
Subroutine wikidata_start_time: not called CC=2 SCAR=17.9
Pod undocumented
825 0 my $self = shift;
826  
827 0 ▶ if (! defined $self->{'transform_object'}->start_time) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->start_time) 0 0 0
828 0 return;
829 }
830  
831 # XXX start_time is every year? Probably not.
832 0 my $start_time = $self->{'transform_object'}->start_time;
833  
834 0 return $self->_year($start_time, 'start time', 'P580');
835 }
836  
837 0 ▶sub wikidata_subtitles {
Subroutine wikidata_subtitles: not called CC=3 SCAR=24.8
Pod undocumented
838 0 my $self = shift;
839  
840 0 ▶ if (! @{$self->{'transform_object'}->subtitles}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"transform_object"}->subtitles;}) 0 0 0
841 0 return;
842 }
843  
844 0 my @ret;
845 0 foreach my $subtitle (@{$self->{'transform_object'}->subtitles}) {
846 0 push @ret, Wikibase::Datatype::Statement->new(
847 'references' => [$self->wikidata_reference],
848 'snak' => Wikibase::Datatype::Snak->new(
849 'datatype' => 'monolingualtext',
850 'datavalue' => Wikibase::Datatype::Value::Monolingual->new(
851 'language' => $self->_marc_lang_to_wd_lang,
852 'value' => $subtitle,
853 ),
854 'property' => 'P1680',
855 ),
856 ),
857 }
858  
859 0 return @ret;
860 }
861  
862 0 ▶sub wikidata_title {
Subroutine wikidata_title: not called CC=2 SCAR=17.9
Pod undocumented
863 0 my $self = shift;
864  
865 0 ▶ if (! defined $self->{'transform_object'}->title) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"transform_object"}->title) 0 0 0
866 0 return;
867 }
868  
869 return (
870 Wikibase::Datatype::Statement->new(
871 'references' => [$self->wikidata_reference],
872 'snak' => Wikibase::Datatype::Snak->new(
873 'datatype' => 'monolingualtext',
874 'datavalue' => Wikibase::Datatype::Value::Monolingual->new(
875 'language' => $self->_marc_lang_to_wd_lang,
876 0 'value' => $self->{'transform_object'}->title,
877 ),
878 'property' => 'P1476',
879 ),
880 ),
881 );
882 }
883  
884 0 ▶sub wikidata_translators {
Subroutine wikidata_translators: not called CC=1 SCAR=6.9
Pod undocumented
885 0 my $self = shift;
886  
887 0 return $self->wikidata_people('translators', 'P655');
888 }
889  
890 0 ▶sub _description {
Subroutine _description: not called CC=1 SCAR=6.9
891 0 my ($self, $lang) = @_;
892  
893 0 err "Method _description() is abstract, you need to implement.";
894 }
895  
896 0 ▶sub _isbn_publisher {
Subroutine _isbn_publisher: not called CC=3 SCAR=24.8
897 0 my ($self, $isbn_o) = @_;
898  
899 0 ▶ if (! defined $isbn_o->publisher) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isbn_o->publisher) 0 0 0
900 0 return;
901 }
902  
903 0 my ($publisher) = $self->_publisher_translate(
904 $isbn_o->publisher
905 );
906 0 ▶ if (! defined $publisher) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $publisher) 0 0 0
907 0 return;
908 }
909  
910 0 return $publisher;
911 }
912  
913 0 ▶sub _isbn_cover {
Subroutine _isbn_cover: not called CC=2 SCAR=17.9
914 0 my ($self, $isbn_o) = @_;
915  
916 0 ▶ if (! defined $isbn_o->cover) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isbn_o->cover) 0 0 0
917 0 return;
918 }
919  
920 0 return $self->_cover_translate($isbn_o->cover);
921 }
922  
923 0 ▶sub _marc_lang_to_wd_lang {
Subroutine _marc_lang_to_wd_lang: not called CC=3 SCAR=24.8
924 0 my $self = shift;
925  
926 0 my $wd_lang;
927 0 my $marc_lang = $self->{'transform_object'}->languages->[0];
928 # TODO Common way. ISO 639-2 code for bibliography
929 0 ▶ if ($marc_lang eq 'cze') {
Branch: 2 branches
BranchTrueFalseTotal
if ($marc_lang eq 'cze') { } 0 0 0
elsif ($marc_lang eq 'eng') { } 0 0 0
930 0 $wd_lang = 'cs';
931 } elsif ($marc_lang eq 'eng') {
932 0 $wd_lang = 'en';
933 }
934  
935 0 return $wd_lang;
936 }
937  
938 0 ▶sub _publisher_translate {
Subroutine _publisher_translate: not called CC=4 SCAR=30.0
939 0 my ($self, @publishers) = @_;
940  
941 0 my @publisher_qids;
942 0 my $publication_date = $self->{'transform_object'}->publication_date;
943 0 ▶ if (! defined $self->{'callback_publisher_name'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'callback_publisher_name'}) { } 0 0 0
944 0 return;
945 } else {
946 0 foreach my $publisher (@publishers) {
947 0 my $publisher_qid = $self->{'callback_publisher_name'}->($publisher, $publication_date);
948 0 ▶ if ($publisher_qid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($publisher_qid) 0 0 0
949 0 push @publisher_qids, [$publisher_qid, $publisher->name];
950 }
951 }
952 }
953  
954 0 return @publisher_qids;
955 }
956  
957 0 ▶sub _cover_translate {
Subroutine _cover_translate: not called CC=2 SCAR=17.9
958 0 my ($self, $cover) = @_;
959  
960 0 my $cover_qid;
961 0 ▶ if (! defined $self->{'callback_cover'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'callback_cover'}) { } 0 0 0
962 0 return;
963 } else {
964 0 $cover_qid = $self->{'callback_cover'}->($cover);
965 }
966  
967 0 return $cover_qid;
968 }
969  
970 0 ▶sub _year {
Subroutine _year: not called CC=2 SCAR=17.9
971 0 my ($self, $year, $title, $property) = @_;
972  
973 0 my $value_dt = eval {
974 0 DateTime->new(
975 'year' => $year,
976 );
977 };
978 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MARC::Convert::Wikidata::Item::EVAL_ERROR) 0 0 0
979 0 return;
980 0 err "Cannot process $title '$year'.",
981 'Error', $EVAL_ERROR;
982 }
983 0 my $value = '+'.$value_dt->iso8601().'Z';
984 return (
985 0 Wikibase::Datatype::Statement->new(
986 'references' => [$self->wikidata_reference],
987 'snak' => Wikibase::Datatype::Snak->new(
988 'datatype' => 'time',
989 'datavalue' => Wikibase::Datatype::Value::Time->new(
990 # Precision for year.
991 'precision' => 9,
992 'value' => $value,
993 ),
994 'property' => $property,
995 ),
996 ),
997 );
998 }
999  
1000 21 1;
1001  
1002 __END__
↑ Summary Wikidata/Item/BookEdition.pm »