Wikidata/Transform.pm

filter: Statementstmt 97.5% 320 / 328 Branchbran 82.9% 73 / 88 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 51 / 51 Podpod 0.0% 0 / 2 totaltotal 93.2% 456 / 489 CC 66 SCAR 14.6
CC
66
Cov
94%
_isbns
11.1
_process_people
8.0
_covers
7.0
CRAP 4.3
« Wikidata/Utils.pm ↑ Summary Wikidata/Item/Periodical.pm »
1 package MARC::Convert::Wikidata::Transform;
2  
3 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 32 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 32 ▶use Data::Kramerius;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use List::Util 1.33 qw(any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use MARC::Convert::Wikidata::Object 0.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 32 ▶use MARC::Convert::Wikidata::Object::ExternalId 0.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 32 ▶use MARC::Convert::Wikidata::Object::ISBN;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 32 ▶use MARC::Convert::Wikidata::Object::Kramerius;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 32 ▶use MARC::Convert::Wikidata::Object::People;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 32 ▶use MARC::Convert::Wikidata::Object::Publisher;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 32 ▶use MARC::Convert::Wikidata::Object::Series 0.15;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 32 use MARC::Convert::Wikidata::Utils qw(clean_cover clean_date clean_edition_number
18 clean_isbn clean_issn clean_number_of_pages clean_oclc clean_publication_date
19 clean_publisher_name clean_publisher_place clean_series_name clean_series_ordinal
20 32 ▶ clean_subtitle clean_title);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶use MARC::Field008 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 32 ▶use MARC::Leader 0.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 32 ▶use Mo::utils 0.08 qw(check_isa check_required);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 32 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 32 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 32 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 32 ▶use Unicode::UTF8 qw(decode_utf8 encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 32 Readonly::Array our @COVERS => qw(hardback paperback);
30 32 Readonly::Hash our %PEOPLE_TYPE => {
31 'aft' => 'authors_of_afterword',
32 'aui' => 'authors_of_introduction',
33 'aut' => 'authors',
34 'com' => 'compilers',
35 'drt' => 'directors',
36 'edt' => 'editors',
37 'ill' => 'illustrators',
38 'nrt' => 'narrators',
39 'pht' => 'photographers',
40 'trl' => 'translators',
41 };
42  
43 32 our $VERSION = 0.33;
44  
45 # Constructor.
46 sub new {
47 31 ▶ my ($class, @params) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
48  
49 # Create object.
50 31 my $self = bless {}, $class;
51  
52 # Ignore data errors.
53 31 $self->{'ignore_data_errors'} = 0;
54  
55 # MARC::Record object.
56 31 $self->{'marc_record'} = undef;
57  
58 # Process parameters.
59 31 set_params($self, @params);
60  
61 # Check 'marc_record'.
62 31 check_required($self, 'marc_record');
63 30 check_isa($self, 'marc_record', 'MARC::Record');
64  
65 28 $self->{'_kramerius'} = Data::Kramerius->new;
66  
67 28 $self->_process_leader;
68 28 $self->_process_field008;
69  
70 # Process people in 100, 700.
71 28 $self->{'_people'} = {
72 'authors' => [],
73 'authors_of_afterword' => [],
74 'authors_of_introduction' => [],
75 'compilers' => [],
76 'directors' => [],
77 'editors' => [],
78 'illustrators' => [],
79 'narrators' => [],
80 'photographers' => [],
81 'translators' => [],
82 };
83 28 $self->_process_people_100;
84 28 $self->_process_people_700;
85  
86 28 $self->{'_object'} = undef;
87 28 $self->_process_object;
88  
89 28 return $self;
90 }
91  
92 sub object {
93 26 ▶ my $self = shift;
Subroutine object: called CC=1 SCAR=0.0
Pod undocumented
94  
95 26 return $self->{'_object'};
96 }
97  
98 sub _ccnb {
99 28 ▶ my $self = shift;
Subroutine _ccnb: called CC=3 SCAR=11.0
100  
101 28 my @ret;
102  
103 28 my $ccnb = $self->_subfield('015', 'a');
104 28 ▶ if (defined $ccnb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ccnb) 28 0 28
105 28 push @ret, MARC::Convert::Wikidata::Object::ExternalId->new(
106 'name' => 'cnb',
107 'value' => $ccnb,
108 );
109 }
110  
111 28 my @depr_ccnb = $self->_subfield('015', 'z');
112 28 foreach my $depr_ccnb (@depr_ccnb) {
113 6 push @ret, MARC::Convert::Wikidata::Object::ExternalId->new(
114 'deprecated' => 1,
115 'name' => 'cnb',
116 'value' => $depr_ccnb,
117 );
118 }
119  
120 28 return @ret;
121 }
122  
123 sub _construct_kramerius {
124 14 ▶ my ($self, $kramerius_uri) = @_;
Subroutine _construct_kramerius: called CC=3 SCAR=11.0
125  
126 # XXX krameriusndk.nkp.cz is virtual project domain.
127 14 $kramerius_uri =~ s/krameriusndk\.nkp\.cz/kramerius.mzk.cz/ms;
128  
129 14 my $u = URI->new($kramerius_uri);
130 14 my $authority = $u->authority;
131 14 foreach my $k ($self->{'_kramerius'}->list) {
132 232 ▶ if ($k->url =~ m/$authority\/$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->url =~ m[$authority/$]ms) 14 218 232
133 14 my @path_seg = $u->path_segments;
134 14 my $uuid = $path_seg[-1];
135 14 $uuid =~ s/^uuid://ms;
136 14 return MARC::Convert::Wikidata::Object::Kramerius->new(
137 'kramerius_id' => $k->id,
138 'object_id' => $uuid,
139 'url' => $kramerius_uri,
140 );
141 }
142 }
143  
144 0 return;
145 }
146  
147 sub _covers {
148 28 ▶ my $self = shift;
Subroutine _covers: called CC=7 SCAR=19.5
149  
150 28 my @cover = $self->_subfield('020', 'q');
151 28 my @ret_cover;
152 28 foreach my $cover (@cover) {
153 27 $cover = clean_cover($cover);
154 27 ▶ if (! defined $cover) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cover) 3 24 27
155 3 next;
156 }
157 24 ▶ if ($cover eq 'hardback' || $cover eq 'paperback') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cover eq 'hardback' or $cover eq 'paperback') { } 23 1 24
elsif ($cover eq 'collective') { } 1 0 1
Condition100%3/3
$cover eq "hardback" or $cover eq "paperback"
l!l&&r!l&&!r
9141
MC/DC100%2/2
$cover eq "hardback" or $cover eq "paperback"
$cover eq "hardback" $cover eq "paperback"
Truth table100%3/3
A or B
A= $cover eq "hardback"B= $cover eq "paperback"
ABresult
1X1
011
000
158 23 ▶ if (none { $_ eq $cover } @ret_cover) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $_ eq $cover; } , @ret_cover)) 22 1 23
159 22 push @ret_cover, $cover;
160 }
161 } elsif ($cover eq 'collective') {
162 # nothing
163 } else {
164 0 warn encode_utf8("Book cover '$cover' doesn't exist.\n");
165 }
166 }
167  
168 28 return @ret_cover;
169 }
170  
171 sub _cycles {
172 28 ▶ my $self = shift;
Subroutine _cycles: called CC=6 SCAR=18.6
173  
174 28 my @cycle_787 = $self->{'marc_record'}->field('787');
175 28 my @cycles;
176 28 foreach my $cycle_787 (@cycle_787) {
177 1 my $marc_787i = $cycle_787->subfield('i');
178 1 ▶ if (defined $marc_787i && $marc_787i =~ m/^Z cyklu:/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $marc_787i and $marc_787i =~ /^Z cyklu:/ms) 1 0 1
Condition33%1/3
defined $marc_787i and $marc_787i =~ /^Z cyklu:/ms
!ll&&!rl&&r
001
MC/DC0%0/2
defined $marc_787i and $marc_787i =~ /^Z cyklu:/ms
defined $marc_787i $marc_787i =~ /^Z cyklu:/ms
Truth table33%1/3
A and B
A= defined $marc_787iB= $marc_787i =~ /^Z cyklu:/ms
ABresult
0X0
100
111
179 1 my $cycle_name = $cycle_787->subfield('t');
180 1 my $cycle_ordinal = $cycle_787->subfield('g');
181  
182 # XXX Over all publishers.
183 1 foreach my $publisher ($self->_publishers) {
184 1 ▶ push @cycles, MARC::Convert::Wikidata::Object::Series->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $publisher ? : 1 0 1
185 'name' => $cycle_name,
186 defined $publisher ? (
187 'publisher' => $publisher,
188 ) : (),
189 'series_ordinal' => $cycle_ordinal,
190 'series_ordinal_raw' => $cycle_ordinal,
191 );
192 }
193 }
194 }
195  
196 28 return @cycles;
197 }
198  
199 sub _dml {
200 28 ▶ my $self = shift;
Subroutine _dml: called CC=3 SCAR=11.3
201  
202 28 my @fields_856 = $self->{'marc_record'}->field('856');
203 28 foreach my $field_856 (@fields_856) {
204 14 my $uri = $field_856->subfield('u');
205 14 ▶ if ($uri =~ m/https:\/\/dml\.cz\/handle\/10338\.dmlcz\/(\d+)$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ m[https://dml\.cz/handle/10338\.dmlcz/(\d+)$]ms) 0 14 14
206 0 return $1;
207 }
208 }
209  
210 28 return;
211 }
212  
213 sub _edition_number {
214 41 ▶ my $self = shift;
Subroutine _edition_number: called CC=4 SCAR=13.9
215  
216 41 my $edition_number = $self->_subfield('250', 'a');
217 41 ▶ if (! defined $edition_number) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $edition_number) 10 31 41
218 10 return;
219 }
220 31 my $orig_edition_number = $edition_number;
221 31 $edition_number = clean_edition_number($edition_number);
222  
223 31 ▶ if (! defined $edition_number) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $edition_number) { } 5 26 31
elsif (not $edition_number =~ /^\d+$/ms) { } 0 26 26
224 5 warn encode_utf8("Edition number '$orig_edition_number' cannot clean.\n");
225 } elsif ($edition_number !~ m/^\d+$/ms) {
226 0 warn encode_utf8("Edition number '$edition_number' isn't number.\n");
227 }
228  
229 31 return $edition_number;
230 }
231  
232 sub _isbns {
233 28 ▶ my $self = shift;
Subroutine _isbns: called CC=11 SCAR=24.1
234  
235 28 my @isbn_fields = $self->{'marc_record'}->field('020');
236 28 my @ret_isbns;
237 28 foreach my $isbn_field (@isbn_fields) {
238 25 my $isbn = $isbn_field->subfield('a');
239 25 my $valid = 1;
240 25 ▶ if (! defined $isbn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isbn) 11 14 25
241 11 $isbn = $isbn_field->subfield('z');
242 11 ▶ if (! defined $isbn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isbn) 10 1 11
243 10 next;
244 }
245 1 $valid = 0;
246 }
247 15 $isbn = clean_isbn($isbn);
248 15 my @publishers = $isbn_field->subfield('q');
249 15 my ($publisher, $cover, $collective) = (undef, undef, 0);
250 15 foreach my $pub (@publishers) {
251 17 $pub = clean_cover($pub);
252 17 ▶ if (! defined $pub) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pub) 3 14 17
253 3 next;
254 }
255 14 ▶ if (any { $pub eq $_ } @COVERS) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
if (&any(sub { $pub eq $_; } , @MARC::Convert::Wikidata::Transform::COVERS)) { } 13 1 14
elsif ($pub eq 'collective') { } 1 0 1
256 13 $cover = $pub;
257 } elsif ($pub eq 'collective') {
258 1 $collective = 1;
259 } else {
260 0 $publisher = $pub;
261 }
262 }
263 15 ▶ my $isbn_o = MARC::Convert::Wikidata::Object::ISBN->new(
Branch: 2 branches
BranchTrueFalseTotal
defined $cover ? : 13 2 15
defined $publisher ? : 0 15 15
264 'collective' => $collective,
265 defined $cover ? (
266 'cover' => $cover,
267 ) : (),
268 'isbn' => $isbn,
269 defined $publisher ? (
270 'publisher' => MARC::Convert::Wikidata::Object::Publisher->new(
271 'name' => clean_publisher_name($publisher),
272 ),
273 ) : (),
274 'valid' => $valid,
275 );
276 15 ▶ if (defined $isbn_o) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $isbn_o) 15 0 15
277 15 push @ret_isbns, $isbn_o;
278 }
279 }
280  
281 28 return (@ret_isbns);
282 }
283  
284 sub _issn {
285 28 ▶ my $self = shift;
Subroutine _issn: called CC=1 SCAR=0.0
286  
287 28 my $issn = $self->_subfield('022', 'a');
288  
289 28 return $issn;
290 }
291  
292 sub _krameriuses {
293 28 ▶ my $self = shift;
Subroutine _krameriuses: called CC=1 SCAR=0.0
294  
295 return map {
296 28 $self->_construct_kramerius($_);
297 } $self->_subfield('856', 'u');
298 }
299  
300 sub _languages {
301 28 ▶ my $self = shift;
Subroutine _languages: called CC=2 SCAR=6.9
302  
303 28 my @lang = $self->_subfield('041', 'a');
304 28 ▶ if (! @lang) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@lang) 12 16 28
305 12 push @lang, $self->_subfield('040', 'b');
306 }
307  
308 28 return @lang;
309 }
310  
311 sub _lccn {
312 28 ▶ my $self = shift;
Subroutine _lccn: called CC=2 SCAR=6.9
313  
314 28 my @ret;
315  
316 28 my @lccn = $self->_subfield('035', 'a');
317 28 foreach my $lccn (@lccn) {
318 28 $lccn = clean_oclc($lccn);
319 28 push @ret, MARC::Convert::Wikidata::Object::ExternalId->new(
320 'name' => 'lccn',
321 'value' => $lccn,
322 );
323 }
324  
325 28 return @ret;
326 }
327  
328 sub _number_of_pages {
329 28 ▶ my $self = shift;
Subroutine _number_of_pages: called CC=1 SCAR=0.0
330  
331 28 my $number_of_pages = $self->_subfield('300', 'a');
332 28 $number_of_pages = clean_number_of_pages($number_of_pages);
333  
334 28 return $number_of_pages;
335 }
336  
337 sub _process_field008 {
338 28 ▶ my $self = shift;
Subroutine _process_field008: called CC=2 SCAR=7.1
339  
340 28 my $field008 = $self->{'marc_record'}->field('008');
341 28 ▶ if (! defined $field008) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field008) 0 28 28
342 err "Field 008 isn't present.",
343 0 'MARC', $self->{'marc_record'}->as_formatted,
344 ;
345 }
346 28 my $field008_string = $field008->as_string;
347  
348 $self->{'_field008'} = MARC::Field008->new(
349 'ignore_data_errors' => $self->{'ignore_data_errors'},
350 28 'leader' => $self->{'_leader'},
351 )->parse($field008_string);
352  
353 28 return;
354 }
355  
356 sub _process_leader {
357 28 ▶ my $self = shift;
Subroutine _process_leader: called CC=1 SCAR=0.0
358  
359 28 my $leader_string = $self->{'marc_record'}->leader;
360  
361 28 $self->{'_leader'} = MARC::Leader->new->parse($leader_string);
362  
363 28 return;
364 }
365  
366 sub _process_object {
367 28 ▶ my $self = shift;
Subroutine _process_object: called CC=5 SCAR=16.2
368  
369 28 my ($publication_date, $publication_date_option) = $self->_publication_date;
370 28 my ($start_time, $end_time);
371 28 ▶ if ($publication_date =~ m/^(\d+)\-(\d*)$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($publication_date =~ /^(\d+)\-(\d*)$/ms) 5 23 28
372 5 $start_time = $1;
373 5 ▶ if ($2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 5 0 5
374 5 $end_time = $2;
375 }
376 5 undef $publication_date;
377 }
378  
379 # TODO $publication_date_option; end_time; start_time
380 $self->{'_object'} = MARC::Convert::Wikidata::Object->new(
381 'authors' => $self->{'_people'}->{'authors'},
382 'authors_of_afterword' => $self->{'_people'}->{'authors_of_afterword'},
383 'authors_of_introduction' => $self->{'_people'}->{'authors_of_introduction'},
384 'compilers' => $self->{'_people'}->{'compilers'},
385 'covers' => [$self->_covers],
386 'cycles' => [$self->_cycles],
387 'directors' => $self->{'_people'}->{'directors'},
388 $self->_dml ? ('dml' => $self->_dml) : (),
389 $self->_edition_number ? ('edition_number' => $self->_edition_number) : (),
390 'editors' => $self->{'_people'}->{'editors'},
391 'end_time' => $end_time,
392 'external_ids' => [
393 $self->_ccnb,
394 $self->_lccn,
395 ],
396 'isbns' => [$self->_isbns],
397 'issn' => $self->_issn,
398 'illustrators' => $self->{'_people'}->{'illustrators'},
399 'krameriuses' => [$self->_krameriuses],
400 'languages' => [$self->_languages],
401 'narrators' => $self->{'_people'}->{'narrators'},
402 'number_of_pages' => $self->_number_of_pages,
403 'photographers' => $self->{'_people'}->{'photographers'},
404 'publication_date' => $publication_date,
405 'publishers' => [$self->_publishers],
406 'series' => [$self->_series],
407 'start_time' => $start_time,
408 'subtitles' => [$self->_subtitles],
409 'title' => $self->_title,
410 28 ▶ 'translators' => $self->{'_people'}->{'translators'},
Branch: 2 branches
BranchTrueFalseTotal
$self->_dml ? : 0 28 28
$self->_edition_number ? : 13 15 28
411 );
412  
413 28 return;
414 }
415  
416 sub _process_people {
417 50 ▶ my ($self, $field) = @_;
Subroutine _process_people: called CC=8 SCAR=20.8
418  
419 50 my @types = $field->subfield('4');
420 50 my @type_keys;
421 50 foreach my $type (@types) {
422 46 my $type_key = $self->_process_people_type($type);
423 46 ▶ if (defined $type_key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_key) 45 1 46
424 45 push @type_keys, $type_key;
425 }
426 }
427 50 ▶ if (! @type_keys) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@type_keys) 10 40 50
428 10 return;
429 }
430  
431 40 my $full_name = $field->subfield('a');
432 # TODO Only if type 1. Fix for type 0 and 2.
433 40 my ($surname, $name) = split m/,\s*/ms, $full_name;
434  
435 40 my $nkcr_aut = $field->subfield('7');
436  
437 40 my $dates = $field->subfield('d');
438 40 my ($date_of_birth, $date_of_death, $work_period_start, $work_period_end);
439 40 ▶ if (defined $dates) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dates) 30 10 40
440 30 my $active_re = decode_utf8('činný');
441 30 ▶ if ($dates =~ m/^$active_re\s*(.*)/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dates =~ /^$active_re\s*(.*)/ms) { } 1 29 30
442 1 my ($start_date, $end_date) = split m/-/ms, $1;
443 1 $work_period_start = clean_date($start_date);
444 1 $work_period_end = clean_date($end_date);
445 } else {
446 29 my ($start_date, $end_date) = split m/-/ms, $dates;
447 29 $date_of_birth = clean_date($start_date);
448 29 $date_of_death = clean_date($end_date);
449 }
450 }
451  
452 40 foreach my $type_key (@type_keys) {
453 45 ▶ push @{$self->{'_people'}->{$type_key}},
Branch: 1 branch
BranchTrueFalseTotal
defined $nkcr_aut ? : 41 4 45
454 MARC::Convert::Wikidata::Object::People->new(
455 'date_of_birth' => $date_of_birth,
456 'date_of_death' => $date_of_death,
457 defined $nkcr_aut ? (
458 'external_ids' => [
459 MARC::Convert::Wikidata::Object::ExternalId->new(
460 'name' => 'nkcr_aut',
461 'value' => $nkcr_aut,
462 ),
463 ],
464 ) : (),
465 'work_period_start' => $work_period_start,
466 'work_period_end' => $work_period_end,
467 'name' => $name,
468 'surname' => $surname,
469 );
470 }
471  
472 40 return;
473 }
474  
475 sub _process_people_100 {
476 28 ▶ my $self = shift;
Subroutine _process_people_100: called CC=2 SCAR=6.9
477  
478 28 my @field_100 = $self->{'marc_record'}->field('100');
479 28 foreach my $field (@field_100) {
480 22 $self->_process_people($field);
481 }
482  
483 28 return;
484 }
485  
486 sub _process_people_700 {
487 28 ▶ my $self = shift;
Subroutine _process_people_700: called CC=2 SCAR=6.9
488  
489 28 my @field_700 = $self->{'marc_record'}->field('700');
490 28 foreach my $field (@field_700) {
491 28 $self->_process_people($field);
492 }
493  
494 28 return;
495 }
496  
497 sub _process_people_type {
498 46 ▶ my ($self, $type) = @_;
Subroutine _process_people_type: called CC=4 SCAR=15.2
499  
500 46 ▶ if (! defined $type || $type eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $type or $type eq "") 0 46 46
Condition33%1/3
not defined $type or $type eq ""
l!l&&r!l&&!r
0046
MC/DC0%0/2
not defined $type or $type eq ""
not defined $type $type eq ""
Truth table33%1/3
not(A) or B
A= not defined $typeB= $type eq ""
ABresult
1X1
011
000
501 0 warn "People type set to 'aut'.\n";
502 0 $type = 'aut';
503 }
504  
505 46 ▶ if (exists $PEOPLE_TYPE{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $MARC::Convert::Wikidata::Transform::PEOPLE_TYPE{$type}) { } 45 1 46
506 45 return $PEOPLE_TYPE{$type};
507 } else {
508 1 warn "People type '$type' doesn't exist.\n";
509 1 return;
510 }
511 }
512  
513 sub _process_publisher_field {
514 82 ▶ my ($self, $field_num) = @_;
Subroutine _process_publisher_field: called CC=4 SCAR=13.9
515  
516 82 my $field = $self->{'marc_record'}->field($field_num);
517 82 ▶ if (! defined $field) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field) 41 41 82
518 41 return ();
519 }
520 41 my @publisher_names = $field->subfield('b');
521 41 my @publishers;
522 41 ▶ for (my $i = 0; $i < @publisher_names; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @publisher_names) 43 41 84
523 43 my $publisher_name = clean_publisher_name($publisher_names[$i]);
524  
525 43 my @places = $field->subfield('a');
526 43 my $place;
527 43 ▶ if (defined $places[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $places[$i]) { } 41 2 43
528 41 $place = $places[$i];
529 } else {
530 2 $place = $places[0];
531 }
532 43 $place = clean_publisher_place($place);
533  
534 43 push @publishers, MARC::Convert::Wikidata::Object::Publisher->new(
535 'name' => $publisher_name,
536 'place' => $place,
537 );
538 }
539  
540 41 return @publishers;
541 }
542  
543 sub _publication_date {
544 28 ▶ my $self = shift;
Subroutine _publication_date: called CC=4 SCAR=13.9
545  
546 28 my $publication_date = $self->{'_field008'}->date1;
547 28 ▶ if ($self->{'_field008'}->date2 ne ' '
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_field008"}->date2 ne " " and $self->{"_field008"}->type_of_date ne "t") 5 23 28
Condition100%3/3
$self->{"_field008"}->date2 ne " " and $self->{"_field008"}->type_of_date ne "t"
!ll&&!rl&&r
2125
MC/DC100%2/2
$self->{"_field008"}->date2 ne " " and $self->{"_field008"}->type_of_date ne "t"
$self->{"_field008"}->date2 ne " " $self->{"_field008"}->type_of_date ne "t"
Truth table100%3/3
A and B
A= $self->{"_field008"}->date2 ne " "B= $self->{"_field008"}->type_of_date ne "t"
ABresult
0X0
100
111
548  
549 # Copyright date.
550 && $self->{'_field008'}->type_of_date ne 't') {
551  
552 5 $publication_date .= '-'.$self->{'_field008'}->date2;
553 }
554 # my $publication_date = $self->_subfield('264', 'c');
555 # if (! $publication_date) {
556 # $publication_date = $self->_subfield('260', 'c');
557 # }
558  
559 28 my $option;
560 # ($publication_date, $option) = clean_publication_date($publication_date);
561  
562 28 ▶ return wantarray ? ($publication_date, $option) : $publication_date;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 28 0 28
563 }
564  
565 sub _publishers {
566 41 ▶ my $self = shift;
Subroutine _publishers: called CC=1 SCAR=0.0
567  
568 41 my @publishers = $self->_process_publisher_field('260');
569 41 push @publishers, $self->_process_publisher_field('264');
570  
571 41 return @publishers;
572 }
573  
574 sub _series {
575 28 ▶ my $self = shift;
Subroutine _series: called CC=5 SCAR=16.1
576  
577 28 my @series_830 = $self->{'marc_record'}->field('830');
578  
579 28 my @series_490 = $self->{'marc_record'}->field('490');
580 28 my @series;
581 28 foreach my $series_490 (@series_490) {
582 12 my $series_name = $series_490->subfield('a');
583 12 $series_name = clean_series_name($series_name);
584 12 my $series_ordinal_raw = $series_490->subfield('v');
585 12 my $series_ordinal = clean_series_ordinal($series_ordinal_raw);
586 12 my $issn = $series_490->subfield('x');
587 12 $issn = clean_issn($issn);
588  
589 # XXX Over all publishers.
590 12 foreach my $publisher ($self->_publishers) {
591 13 ▶ push @series, MARC::Convert::Wikidata::Object::Series->new(
Branch: 2 branches
BranchTrueFalseTotal
defined $issn ? : 2 11 13
defined $publisher ? : 13 0 13
592 defined $issn ? (
593 'issn' => $issn,
594 ) : (),
595 'name' => $series_name,
596 defined $publisher ? (
597 'publisher' => $publisher,
598 ) : (),
599 'series_ordinal' => $series_ordinal,
600 'series_ordinal_raw' => $series_ordinal_raw,
601 );
602 }
603 }
604  
605 28 return @series;
606 }
607  
608 sub _subfield {
609 389 ▶ my ($self, $field, $subfield) = @_;
Subroutine _subfield: called CC=4 SCAR=13.9
610  
611 389 my @ret;
612  
613 389 my @field_values = $self->{'marc_record'}->field($field);
614 389 foreach my $field_value (@field_values) {
615 324 my @subfield_values = $field_value->subfield($subfield);
616 324 foreach my $subfield_value (@subfield_values) {
617 242 push @ret, $subfield_value;
618 }
619 }
620  
621 389 ▶ return wantarray ? @ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 152 237 389
622 }
623  
624 sub _subtitles {
625 28 ▶ my $self = shift;
Subroutine _subtitles: called CC=4 SCAR=13.9
626  
627 28 my @ret;
628 28 my $subtitle = $self->_subfield('245', 'b');
629 28 $subtitle = clean_subtitle($subtitle);
630 28 ▶ if (defined $subtitle) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subtitle) 15 13 28
631 15 push @ret, $subtitle;
632 }
633 28 my $number_of_part = $self->_subfield('245', 'n');
634 28 $number_of_part = clean_subtitle($number_of_part);
635 28 ▶ if (defined $number_of_part) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $number_of_part) 1 27 28
636 1 push @ret, $number_of_part;
637 }
638 28 my $name_of_part = $self->_subfield('245', 'p');
639 28 $name_of_part = clean_subtitle($name_of_part);
640 28 ▶ if (defined $name_of_part) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name_of_part) 1 27 28
641 1 push @ret, $name_of_part;
642 }
643  
644 28 return @ret;
645 }
646  
647 sub _title {
648 28 ▶ my $self = shift;
Subroutine _title: called CC=1 SCAR=0.0
649  
650 28 my $title = $self->_subfield('245', 'a');
651 28 $title = clean_title($title);
652  
653 28 return $title;
654 }
655  
656 32 1;
657  
658 __END__
« Wikidata/Utils.pm ↑ Summary Wikidata/Item/Periodical.pm »