Wikidata/Item.pm

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