| 1 | package MARC::Convert::Wikidata::Transform; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 33 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Data::Kramerius; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 33 | ▶ | use List::Util 1.33 qw(any none); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 33 | ▶ | use MARC::Convert::Wikidata::Object 0.13; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 33 | ▶ | use MARC::Convert::Wikidata::Object::ExternalId 0.05; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use MARC::Convert::Wikidata::Object::ISBN; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 33 | ▶ | use MARC::Convert::Wikidata::Object::Kramerius; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 33 | ▶ | use MARC::Convert::Wikidata::Object::People; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 33 | ▶ | use MARC::Convert::Wikidata::Object::Publisher; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 33 | ▶ | use MARC::Convert::Wikidata::Object::Series 0.15; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 33 | ▶ | use MARC::Convert::Wikidata::Utils qw(clean_cover clean_date clean_edition_number | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 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 | 33 | clean_subtitle clean_title); | |||||||||||||||||||||||||||||||
| 21 | 33 | ▶ | use MARC::Field008 0.03; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 33 | ▶ | use MARC::Leader 0.05; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 33 | ▶ | use Mo::utils 0.08 qw(check_isa check_required); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 33 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 33 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 33 | ▶ | use URI; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 33 | ▶ | use Unicode::UTF8 qw(decode_utf8 encode_utf8); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 33 | Readonly::Array our @COVERS => qw(hardback paperback); | |||||||||||||||||||||||||||||||
| 30 | 33 | 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 | 33 | our $VERSION = 0.34; | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | # Constructor. | ||||||||||||||||||||||||||||||||
| 46 | 32 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 47 | 32 | my ($class, @params) = @_; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | # Create object. | ||||||||||||||||||||||||||||||||
| 50 | 32 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | # Ignore data errors. | ||||||||||||||||||||||||||||||||
| 53 | 32 | $self->{'ignore_data_errors'} = 0; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | # MARC::Record object. | ||||||||||||||||||||||||||||||||
| 56 | 32 | $self->{'marc_record'} = undef; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | # Process parameters. | ||||||||||||||||||||||||||||||||
| 59 | 32 | set_params($self, @params); | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | # Check 'marc_record'. | ||||||||||||||||||||||||||||||||
| 62 | 32 | check_required($self, 'marc_record'); | |||||||||||||||||||||||||||||||
| 63 | 31 | check_isa($self, 'marc_record', 'MARC::Record'); | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 29 | $self->{'_kramerius'} = Data::Kramerius->new; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 29 | $self->_process_leader; | |||||||||||||||||||||||||||||||
| 68 | 29 | $self->_process_field008; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | # Process people in 100, 700. | ||||||||||||||||||||||||||||||||
| 71 | 29 | $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 | 29 | $self->_process_people_100; | |||||||||||||||||||||||||||||||
| 84 | 29 | $self->_process_people_700; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 29 | $self->{'_object'} = undef; | |||||||||||||||||||||||||||||||
| 87 | 29 | $self->_process_object; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 29 | return $self; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 27 | ▶ | sub object { | ||||||||||||||||||||||||||||||
|
Subroutine
object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 93 | 27 | my $self = shift; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 27 | return $self->{'_object'}; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 29 | ▶ | sub _ccnb { | ||||||||||||||||||||||||||||||
|
Subroutine
_ccnb: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 99 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 29 | my @ret; | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 29 | my $ccnb = $self->_subfield('015', 'a'); | |||||||||||||||||||||||||||||||
| 104 | 29 | ▶ | if (defined $ccnb) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | 29 | push @ret, MARC::Convert::Wikidata::Object::ExternalId->new( | |||||||||||||||||||||||||||||||
| 106 | 'name' => 'cnb', | ||||||||||||||||||||||||||||||||
| 107 | 'value' => $ccnb, | ||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 29 | my @depr_ccnb = $self->_subfield('015', 'z'); | |||||||||||||||||||||||||||||||
| 112 | 29 | 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 | 29 | return @ret; | |||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 15 | ▶ | sub _construct_kramerius { | ||||||||||||||||||||||||||||||
|
Subroutine
_construct_kramerius: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 124 | 15 | my ($self, $kramerius_uri) = @_; | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # XXX krameriusndk.nkp.cz is virtual project domain. | ||||||||||||||||||||||||||||||||
| 127 | 15 | $kramerius_uri =~ s/krameriusndk\.nkp\.cz/kramerius.mzk.cz/ms; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 15 | my $u = URI->new($kramerius_uri); | |||||||||||||||||||||||||||||||
| 130 | 15 | my $authority = $u->authority; | |||||||||||||||||||||||||||||||
| 131 | 15 | foreach my $k ($self->{'_kramerius'}->list) { | |||||||||||||||||||||||||||||||
| 132 | 247 | ▶ | if ($k->url =~ m/$authority\/$/ms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 15 | my @path_seg = $u->path_segments; | |||||||||||||||||||||||||||||||
| 134 | 15 | my $uuid = $path_seg[-1]; | |||||||||||||||||||||||||||||||
| 135 | 15 | $uuid =~ s/^uuid://ms; | |||||||||||||||||||||||||||||||
| 136 | 15 | 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 | 29 | ▶ | sub _covers { | ||||||||||||||||||||||||||||||
|
Subroutine
_covers: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 148 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 29 | my @cover = $self->_subfield('020', 'q'); | |||||||||||||||||||||||||||||||
| 151 | 29 | my @ret_cover; | |||||||||||||||||||||||||||||||
| 152 | 29 | foreach my $cover (@cover) { | |||||||||||||||||||||||||||||||
| 153 | 27 | $cover = clean_cover($cover); | |||||||||||||||||||||||||||||||
| 154 | 27 | ▶ | if (! defined $cover) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 3 | next; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | 24 | ▶ | if ($cover eq 'hardback' || $cover eq 'paperback') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$cover eq "hardback" or $cover eq "paperback"
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"
| |||||||||||||||||||||||||||||||||
| 158 | 23 | ▶ | if (none { $_ eq $cover } @ret_cover) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 29 | return @ret_cover; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 29 | ▶ | sub _cycles { | ||||||||||||||||||||||||||||||
|
Subroutine
_cycles: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||
| 172 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 29 | my @cycle_787 = $self->{'marc_record'}->field('787'); | |||||||||||||||||||||||||||||||
| 175 | 29 | my @cycles; | |||||||||||||||||||||||||||||||
| 176 | 29 | 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
Condition33%1/3
defined $marc_787i and $marc_787i =~ /^Z cyklu:/ms
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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 | 29 | return @cycles; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 29 | ▶ | sub _dml { | ||||||||||||||||||||||||||||||
|
Subroutine
_dml: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||
| 200 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 29 | my @fields_856 = $self->{'marc_record'}->field('856'); | |||||||||||||||||||||||||||||||
| 203 | 29 | foreach my $field_856 (@fields_856) { | |||||||||||||||||||||||||||||||
| 204 | 15 | my $uri = $field_856->subfield('u'); | |||||||||||||||||||||||||||||||
| 205 | 15 | ▶ | if ($uri =~ m/https:\/\/dml\.cz\/handle\/10338\.dmlcz\/(\d+)$/ms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | 0 | return $1; | |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 29 | return; | |||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 43 | ▶ | sub _edition_number { | ||||||||||||||||||||||||||||||
|
Subroutine
_edition_number: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 214 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 43 | my $edition_number = $self->_subfield('250', 'a'); | |||||||||||||||||||||||||||||||
| 217 | 43 | ▶ | if (! defined $edition_number) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 10 | return; | |||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | 33 | my $orig_edition_number = $edition_number; | |||||||||||||||||||||||||||||||
| 221 | 33 | $edition_number = clean_edition_number($edition_number); | |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 33 | ▶ | if (! defined $edition_number) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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 | 33 | return $edition_number; | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 29 | ▶ | sub _isbns { | ||||||||||||||||||||||||||||||
|
Subroutine
_isbns: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||
| 233 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 29 | my @isbn_fields = $self->{'marc_record'}->field('020'); | |||||||||||||||||||||||||||||||
| 236 | 29 | my @ret_isbns; | |||||||||||||||||||||||||||||||
| 237 | 29 | 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
| |||||||||||||||||||||||||||||||||
| 241 | 11 | $isbn = $isbn_field->subfield('z'); | |||||||||||||||||||||||||||||||
| 242 | 11 | ▶ | if (! defined $isbn) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 253 | 3 | next; | |||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||
| 255 | 14 | ▶ | if (any { $pub eq $_ } @COVERS) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 277 | 15 | push @ret_isbns, $isbn_o; | |||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 29 | return (@ret_isbns); | |||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 29 | ▶ | sub _issn { | ||||||||||||||||||||||||||||||
|
Subroutine
_issn: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 285 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 29 | my $issn = $self->_subfield('022', 'a'); | |||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | 29 | return $issn; | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 29 | ▶ | sub _krameriuses { | ||||||||||||||||||||||||||||||
|
Subroutine
_krameriuses: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 293 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | return map { | ||||||||||||||||||||||||||||||||
| 296 | 29 | $self->_construct_kramerius($_); | |||||||||||||||||||||||||||||||
| 297 | } $self->_subfield('856', 'u'); | ||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 29 | ▶ | sub _languages { | ||||||||||||||||||||||||||||||
|
Subroutine
_languages: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 301 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 29 | my @lang = $self->_subfield('041', 'a'); | |||||||||||||||||||||||||||||||
| 304 | 29 | ▶ | if (! @lang) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 305 | 13 | push @lang, $self->_subfield('040', 'b'); | |||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 29 | return @lang; | |||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 29 | ▶ | sub _lccn { | ||||||||||||||||||||||||||||||
|
Subroutine
_lccn: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 312 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | 29 | my @ret; | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 29 | my @lccn = $self->_subfield('035', 'a'); | |||||||||||||||||||||||||||||||
| 317 | 29 | foreach my $lccn (@lccn) { | |||||||||||||||||||||||||||||||
| 318 | 29 | $lccn = clean_oclc($lccn); | |||||||||||||||||||||||||||||||
| 319 | 29 | push @ret, MARC::Convert::Wikidata::Object::ExternalId->new( | |||||||||||||||||||||||||||||||
| 320 | 'name' => 'lccn', | ||||||||||||||||||||||||||||||||
| 321 | 'value' => $lccn, | ||||||||||||||||||||||||||||||||
| 322 | ); | ||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | 29 | return @ret; | |||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | 29 | ▶ | sub _number_of_pages { | ||||||||||||||||||||||||||||||
|
Subroutine
_number_of_pages: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 329 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 29 | my $number_of_pages = $self->_subfield('300', 'a'); | |||||||||||||||||||||||||||||||
| 332 | 29 | $number_of_pages = clean_number_of_pages($number_of_pages); | |||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | 29 | return $number_of_pages; | |||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | 29 | ▶ | sub _process_field008 { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_field008: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 338 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | 29 | my $field008 = $self->{'marc_record'}->field('008'); | |||||||||||||||||||||||||||||||
| 341 | 29 | ▶ | if (! defined $field008) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 342 | err "Field 008 isn't present.", | ||||||||||||||||||||||||||||||||
| 343 | 0 | 'MARC', $self->{'marc_record'}->as_formatted, | |||||||||||||||||||||||||||||||
| 344 | ; | ||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | 29 | my $field008_string = $field008->as_string; | |||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | $self->{'_field008'} = MARC::Field008->new( | ||||||||||||||||||||||||||||||||
| 349 | 'ignore_data_errors' => $self->{'ignore_data_errors'}, | ||||||||||||||||||||||||||||||||
| 350 | 29 | 'leader' => $self->{'_leader'}, | |||||||||||||||||||||||||||||||
| 351 | )->parse($field008_string); | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 29 | return; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | 29 | ▶ | sub _process_leader { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_leader: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 357 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | 29 | my $leader_string = $self->{'marc_record'}->leader; | |||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||
| 361 | 29 | $self->{'_leader'} = MARC::Leader->new->parse($leader_string); | |||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||
| 363 | 29 | return; | |||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | 29 | ▶ | sub _process_object { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_object: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 367 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 29 | my ($publication_date, $publication_date_option) = $self->_publication_date; | |||||||||||||||||||||||||||||||
| 370 | 29 | my ($start_time, $end_time); | |||||||||||||||||||||||||||||||
| 371 | 29 | ▶ | if ($publication_date =~ m/^(\d+)\-(\d*)$/ms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 372 | 5 | $start_time = $1; | |||||||||||||||||||||||||||||||
| 373 | 5 | ▶ | if ($2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 29 | ▶ | 'translators' => $self->{'_people'}->{'translators'}, | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 411 | ); | ||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | 29 | return; | |||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | 53 | ▶ | sub _process_people { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_people: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 417 | 53 | my ($self, $field) = @_; | |||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | 53 | my @types = $field->subfield('4'); | |||||||||||||||||||||||||||||||
| 420 | 53 | my @type_keys; | |||||||||||||||||||||||||||||||
| 421 | 53 | foreach my $type (@types) { | |||||||||||||||||||||||||||||||
| 422 | 49 | my $type_key = $self->_process_people_type($type); | |||||||||||||||||||||||||||||||
| 423 | 49 | ▶ | if (defined $type_key) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 424 | 48 | push @type_keys, $type_key; | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | 53 | ▶ | if (! @type_keys) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 428 | 10 | return; | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 43 | my $full_name = $field->subfield('a'); | |||||||||||||||||||||||||||||||
| 432 | # TODO Only if type 1. Fix for type 0 and 2. | ||||||||||||||||||||||||||||||||
| 433 | 43 | my ($surname, $name) = split m/,\s*/ms, $full_name; | |||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | 43 | my $nkcr_aut = $field->subfield('7'); | |||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||
| 437 | 43 | my $dates = $field->subfield('d'); | |||||||||||||||||||||||||||||||
| 438 | 43 | my ($date_of_birth, $date_of_death, $work_period_start, $work_period_end); | |||||||||||||||||||||||||||||||
| 439 | 43 | ▶ | if (defined $dates) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 440 | 30 | my $active_re = decode_utf8('činný'); | |||||||||||||||||||||||||||||||
| 441 | 30 | ▶ | if ($dates =~ m/^$active_re\s*(.*)/ms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 43 | foreach my $type_key (@type_keys) { | |||||||||||||||||||||||||||||||
| 453 | 48 | ▶ | push @{$self->{'_people'}->{$type_key}}, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 43 | return; | |||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||
| 475 | 29 | ▶ | sub _process_people_100 { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_people_100: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 476 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||
| 478 | 29 | my @field_100 = $self->{'marc_record'}->field('100'); | |||||||||||||||||||||||||||||||
| 479 | 29 | foreach my $field (@field_100) { | |||||||||||||||||||||||||||||||
| 480 | 23 | $self->_process_people($field); | |||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | 29 | return; | |||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 29 | ▶ | sub _process_people_700 { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_people_700: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 487 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | 29 | my @field_700 = $self->{'marc_record'}->field('700'); | |||||||||||||||||||||||||||||||
| 490 | 29 | foreach my $field (@field_700) { | |||||||||||||||||||||||||||||||
| 491 | 30 | $self->_process_people($field); | |||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | 29 | return; | |||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||
| 497 | 49 | ▶ | sub _process_people_type { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_people_type: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||
| 498 | 49 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | 49 | ▶ | if (! defined $type || $type eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $type or $type eq ""
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 ""
| |||||||||||||||||||||||||||||||||
| 501 | 0 | warn "People type set to 'aut'.\n"; | |||||||||||||||||||||||||||||||
| 502 | 0 | $type = 'aut'; | |||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | 49 | ▶ | if (exists $PEOPLE_TYPE{$type}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 506 | 48 | return $PEOPLE_TYPE{$type}; | |||||||||||||||||||||||||||||||
| 507 | } else { | ||||||||||||||||||||||||||||||||
| 508 | 1 | warn "People type '$type' doesn't exist.\n"; | |||||||||||||||||||||||||||||||
| 509 | 1 | return; | |||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||
| 513 | 88 | ▶ | sub _process_publisher_field { | ||||||||||||||||||||||||||||||
|
Subroutine
_process_publisher_field: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 514 | 88 | my ($self, $field_num) = @_; | |||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | 88 | my $field = $self->{'marc_record'}->field($field_num); | |||||||||||||||||||||||||||||||
| 517 | 88 | ▶ | if (! defined $field) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 518 | 44 | return (); | |||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||
| 520 | 44 | my @publisher_names = $field->subfield('b'); | |||||||||||||||||||||||||||||||
| 521 | 44 | my @publishers; | |||||||||||||||||||||||||||||||
| 522 | 44 | ▶ | for (my $i = 0; $i < @publisher_names; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 523 | 46 | my $publisher_name = clean_publisher_name($publisher_names[$i]); | |||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||
| 525 | 46 | my @places = $field->subfield('a'); | |||||||||||||||||||||||||||||||
| 526 | 46 | my $place; | |||||||||||||||||||||||||||||||
| 527 | 46 | ▶ | if (defined $places[$i]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 528 | 44 | $place = $places[$i]; | |||||||||||||||||||||||||||||||
| 529 | } else { | ||||||||||||||||||||||||||||||||
| 530 | 2 | $place = $places[0]; | |||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||
| 532 | 46 | $place = clean_publisher_place($place); | |||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | 46 | push @publishers, MARC::Convert::Wikidata::Object::Publisher->new( | |||||||||||||||||||||||||||||||
| 535 | 'name' => $publisher_name, | ||||||||||||||||||||||||||||||||
| 536 | 'place' => $place, | ||||||||||||||||||||||||||||||||
| 537 | ); | ||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | 44 | return @publishers; | |||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||
| 543 | 29 | ▶ | sub _publication_date { | ||||||||||||||||||||||||||||||
|
Subroutine
_publication_date: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 544 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||
| 546 | 29 | my $publication_date = $self->{'_field008'}->date1; | |||||||||||||||||||||||||||||||
| 547 | 29 | ▶ | if ($self->{'_field008'}->date2 ne ' ' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_field008"}->date2 ne " " and $self->{"_field008"}->type_of_date ne "t"
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"
| |||||||||||||||||||||||||||||||||
| 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 | 29 | my $option; | |||||||||||||||||||||||||||||||
| 560 | # ($publication_date, $option) = clean_publication_date($publication_date); | ||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | 29 | ▶ | return wantarray ? ($publication_date, $option) : $publication_date; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | 44 | ▶ | sub _publishers { | ||||||||||||||||||||||||||||||
|
Subroutine
_publishers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 566 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||
| 568 | 44 | my @publishers = $self->_process_publisher_field('260'); | |||||||||||||||||||||||||||||||
| 569 | 44 | push @publishers, $self->_process_publisher_field('264'); | |||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||
| 571 | 44 | return @publishers; | |||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||
| 574 | 29 | ▶ | sub _series { | ||||||||||||||||||||||||||||||
|
Subroutine
_series: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 575 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||
| 577 | 29 | my @series_830 = $self->{'marc_record'}->field('830'); | |||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||
| 579 | 29 | my @series_490 = $self->{'marc_record'}->field('490'); | |||||||||||||||||||||||||||||||
| 580 | 29 | my @series; | |||||||||||||||||||||||||||||||
| 581 | 29 | foreach my $series_490 (@series_490) { | |||||||||||||||||||||||||||||||
| 582 | 14 | my $series_name = $series_490->subfield('a'); | |||||||||||||||||||||||||||||||
| 583 | 14 | $series_name = clean_series_name($series_name); | |||||||||||||||||||||||||||||||
| 584 | 14 | my $series_ordinal_raw = $series_490->subfield('v'); | |||||||||||||||||||||||||||||||
| 585 | 14 | my $series_ordinal = clean_series_ordinal($series_ordinal_raw); | |||||||||||||||||||||||||||||||
| 586 | 14 | my $issn = $series_490->subfield('x'); | |||||||||||||||||||||||||||||||
| 587 | 14 | $issn = clean_issn($issn); | |||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||
| 589 | # XXX Over all publishers. | ||||||||||||||||||||||||||||||||
| 590 | 14 | foreach my $publisher ($self->_publishers) { | |||||||||||||||||||||||||||||||
| 591 | 15 | ▶ | push @series, MARC::Convert::Wikidata::Object::Series->new( | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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 | 29 | return @series; | |||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||
| 608 | 404 | ▶ | sub _subfield { | ||||||||||||||||||||||||||||||
|
Subroutine
_subfield: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 609 | 404 | my ($self, $field, $subfield) = @_; | |||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||
| 611 | 404 | my @ret; | |||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||
| 613 | 404 | my @field_values = $self->{'marc_record'}->field($field); | |||||||||||||||||||||||||||||||
| 614 | 404 | foreach my $field_value (@field_values) { | |||||||||||||||||||||||||||||||
| 615 | 336 | my @subfield_values = $field_value->subfield($subfield); | |||||||||||||||||||||||||||||||
| 616 | 336 | foreach my $subfield_value (@subfield_values) { | |||||||||||||||||||||||||||||||
| 617 | 251 | push @ret, $subfield_value; | |||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||
| 621 | 404 | ▶ | return wantarray ? @ret : $ret[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||
| 624 | 29 | ▶ | sub _subtitles { | ||||||||||||||||||||||||||||||
|
Subroutine
_subtitles: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 625 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||
| 627 | 29 | my @ret; | |||||||||||||||||||||||||||||||
| 628 | 29 | my $subtitle = $self->_subfield('245', 'b'); | |||||||||||||||||||||||||||||||
| 629 | 29 | $subtitle = clean_subtitle($subtitle); | |||||||||||||||||||||||||||||||
| 630 | 29 | ▶ | if (defined $subtitle) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 631 | 16 | push @ret, $subtitle; | |||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||
| 633 | 29 | my $number_of_part = $self->_subfield('245', 'n'); | |||||||||||||||||||||||||||||||
| 634 | 29 | $number_of_part = clean_subtitle($number_of_part); | |||||||||||||||||||||||||||||||
| 635 | 29 | ▶ | if (defined $number_of_part) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 636 | 1 | push @ret, $number_of_part; | |||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||
| 638 | 29 | my $name_of_part = $self->_subfield('245', 'p'); | |||||||||||||||||||||||||||||||
| 639 | 29 | $name_of_part = clean_subtitle($name_of_part); | |||||||||||||||||||||||||||||||
| 640 | 29 | ▶ | if (defined $name_of_part) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 641 | 1 | push @ret, $name_of_part; | |||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||
| 644 | 29 | return @ret; | |||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||
| 647 | 29 | ▶ | sub _title { | ||||||||||||||||||||||||||||||
|
Subroutine
_title: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 648 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||
| 650 | 29 | my $title = $self->_subfield('245', 'a'); | |||||||||||||||||||||||||||||||
| 651 | 29 | $title = clean_title($title); | |||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||
| 653 | 29 | return $title; | |||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||
| 656 | 33 | 1; | |||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||
| 658 | __END__ | ||||||||||||||||||||||||||||||||