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