line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::Convert::Wikidata; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
144115
|
use strict; |
|
3
|
|
|
|
|
28
|
|
|
3
|
|
|
|
|
85
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
892
|
use Class::Utils qw(set_params); |
|
3
|
|
|
|
|
27162
|
|
|
3
|
|
|
|
|
95
|
|
7
|
3
|
|
|
3
|
|
138
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
110
|
|
8
|
3
|
|
|
3
|
|
1423
|
use MARC::Convert::Wikidata::Item::AudioBook; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
115
|
|
9
|
3
|
|
|
3
|
|
1541
|
use MARC::Convert::Wikidata::Item::BookEdition; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
82
|
|
10
|
3
|
|
|
3
|
|
1274
|
use MARC::Convert::Wikidata::Item::Periodical; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
105
|
|
11
|
3
|
|
|
3
|
|
1405
|
use MARC::Convert::Wikidata::Transform; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
130
|
|
12
|
3
|
|
|
3
|
|
20
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2216
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.01; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Constructor. |
17
|
|
|
|
|
|
|
sub new { |
18
|
3
|
|
|
3
|
1
|
25325
|
my ($class, @params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Create object. |
21
|
3
|
|
|
|
|
10
|
my $self = bless {}, $class; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Cover callback. |
24
|
3
|
|
|
|
|
11
|
$self->{'callback_cover'} = undef; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Lang callback. |
27
|
3
|
|
|
|
|
6
|
$self->{'callback_lang'} = undef; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# People callback. |
30
|
3
|
|
|
|
|
6
|
$self->{'callback_people'} = undef; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Place of publication Wikidata lookup callback. |
33
|
3
|
|
|
|
|
6
|
$self->{'callback_publisher_place'} = undef; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Publisher Wikidata lookup callback. |
36
|
3
|
|
|
|
|
6
|
$self->{'callback_publisher_name'} = undef; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Book series Wikidata lookup callback. |
39
|
3
|
|
|
|
|
6
|
$self->{'callback_series'} = undef; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Retrieved date. |
42
|
3
|
|
|
|
|
6
|
$self->{'date_retrieved'} = undef; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# MARC::Record object. |
45
|
3
|
|
|
|
|
8
|
$self->{'marc_record'} = undef; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Process parameters. |
48
|
3
|
|
|
|
|
13
|
set_params($self, @params); |
49
|
|
|
|
|
|
|
|
50
|
3
|
100
|
|
|
|
39
|
if (! defined $self->{'marc_record'}) { |
51
|
1
|
|
|
|
|
5
|
err "Parameter 'marc_record' is required."; |
52
|
|
|
|
|
|
|
} |
53
|
2
|
100
|
66
|
|
|
25
|
if (! blessed($self->{'marc_record'}) |
54
|
|
|
|
|
|
|
|| ! $self->{'marc_record'}->isa('MARC::Record')) { |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
4
|
err "Parameter 'marc_record' must be a MARC::Record object."; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->{'_transform_object'} = MARC::Convert::Wikidata::Transform->new( |
60
|
1
|
|
|
|
|
14
|
'marc_record' => $self->{'marc_record'}, |
61
|
|
|
|
|
|
|
)->object; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
40
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub object { |
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->{'_transform_object'}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub type { |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $leader = $self->{'marc_record'}->leader; |
76
|
|
|
|
|
|
|
# XXX Use MARC::Leader if exist. |
77
|
0
|
|
|
|
|
|
my $leader_hr = $self->_leader($leader); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Language material |
80
|
0
|
0
|
0
|
|
|
|
if ($leader_hr->{'type_of_record'} eq 'a' && $leader_hr->{'bibliographic_level'} eq 'm') { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return 'monograph'; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# XXX Notated music |
84
|
|
|
|
|
|
|
} elsif ($leader_hr->{'type_of_record'} eq 'c' && $leader_hr->{'bibliographic_level'} eq 'm') { |
85
|
0
|
|
|
|
|
|
return 'monograph'; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Nonmusical sound recording |
88
|
|
|
|
|
|
|
} elsif ($leader_hr->{'type_of_record'} eq 'i' && $leader_hr->{'bibliographic_level'} eq 'm') { |
89
|
0
|
|
|
|
|
|
return 'audiobook'; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Serial |
92
|
|
|
|
|
|
|
} elsif ($leader_hr->{'bibliographic_level'} eq 's') { |
93
|
0
|
|
|
|
|
|
return 'periodical'; |
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
err "Unsupported item with leader '$leader'."; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub wikidata { |
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Parameters. |
103
|
|
|
|
|
|
|
my %params = ( |
104
|
|
|
|
|
|
|
'callback_cover' => $self->{'callback_cover'}, |
105
|
|
|
|
|
|
|
'callback_lang' => $self->{'callback_lang'},, |
106
|
|
|
|
|
|
|
'callback_publisher_place' => $self->{'callback_publisher_place'},, |
107
|
|
|
|
|
|
|
'callback_people' => $self->{'callback_people'}, |
108
|
|
|
|
|
|
|
'callback_publisher_name' => $self->{'callback_publisher_name'}, |
109
|
|
|
|
|
|
|
'callback_series' => $self->{'callback_series'}, |
110
|
|
|
|
|
|
|
'marc_record' => $self->{'marc_record'}, |
111
|
0
|
|
|
|
|
|
'transform_object' => $self->{'_transform_object'}, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $wikidata; |
115
|
0
|
|
|
|
|
|
my $marc_type = $self->type; |
116
|
0
|
0
|
|
|
|
|
if ($marc_type eq 'monograph') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$wikidata = MARC::Convert::Wikidata::Item::BookEdition->new( |
118
|
|
|
|
|
|
|
%params, |
119
|
|
|
|
|
|
|
)->wikidata; |
120
|
|
|
|
|
|
|
} elsif ($marc_type eq 'audiobook') { |
121
|
0
|
|
|
|
|
|
$wikidata = MARC::Convert::Wikidata::Item::AudioBook->new( |
122
|
|
|
|
|
|
|
%params, |
123
|
|
|
|
|
|
|
)->wikidata; |
124
|
|
|
|
|
|
|
} elsif ($marc_type eq 'periodical') { |
125
|
0
|
|
|
|
|
|
$wikidata = MARC::Convert::Wikidata::Item::Periodical->new( |
126
|
|
|
|
|
|
|
%params, |
127
|
|
|
|
|
|
|
)->wikidata; |
128
|
|
|
|
|
|
|
} else { |
129
|
0
|
|
|
|
|
|
err "Item '$marc_type' doesn't supported."; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $wikidata; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _leader { |
136
|
0
|
|
|
0
|
|
|
my ($self, $leader) = @_; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Example '03691nam a2200685 aa4500' |
139
|
0
|
|
|
|
|
|
my $length = substr $leader, 0, 5; |
140
|
0
|
|
|
|
|
|
my $record_status = substr $leader, 5, 1; |
141
|
0
|
|
|
|
|
|
my $type_of_record = substr $leader, 6, 1; |
142
|
0
|
|
|
|
|
|
my $bibliographic_level = substr $leader, 7, 1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
return { |
145
|
0
|
|
|
|
|
|
'length' => $length, |
146
|
|
|
|
|
|
|
'record_status' => $record_status, |
147
|
|
|
|
|
|
|
'type_of_record' => $type_of_record, |
148
|
|
|
|
|
|
|
'bibliographic_level' => $bibliographic_level, |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=pod |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=encoding utf8 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 NAME |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
MARC::Convert::Wikidata - Conversion class between MARC file to Wikibase::Datatype item. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SYNOPSIS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
use MARC::Convert::Wikidata; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $obj = MARC::Convert::Wikidata->new(%params); |
169
|
|
|
|
|
|
|
my $object = $obj->object; |
170
|
|
|
|
|
|
|
my $type = $obj->type; |
171
|
|
|
|
|
|
|
my $wikidata = $obj->wikidata; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 DESCRIPTION |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Original intent of this class was conversion from MARC records in National Library of the |
176
|
|
|
|
|
|
|
Czech Republic to Wikidata. The conversion is not simple, this mean that many |
177
|
|
|
|
|
|
|
things are concrete for this concrete national library. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 METHODS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 C<new> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $obj = MARC::Convert::Wikidata->new(%params); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Constructor. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over 8 |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * C<callback_cover> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Cover callback |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Default value is undef. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * C<callback_lang> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Language callback. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Default value is undef. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * C<callback_people> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
People callback. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Default value is undef. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * C<callback_publisher_place> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Place of publication Wikidata lookup callback. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Default value is undef. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * C<callback_publisher_name> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Publisher Wikidata lookup callback. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Default value is undef. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * C<callback_series> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Book series Wikidata lookup callback. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Default value is undef. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * C<date_retrieved> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Retrieved date. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Default value is undef. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * C<marc_record> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
MARC::Record object. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
It's required. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Returns instance of object. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 C<object> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
my $object = $obj->object; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Get data object created from MARC record. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Returns MARC::Convert::Wikidata::Object instance. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 C<type> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
my $type = $obj->type; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Process MARC record and detect which record type is. |
254
|
|
|
|
|
|
|
Supported values are: monograph, audiobook and periodical. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Returns string. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 C<wikidata> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my $wikidata = $obj->wikidata; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Process conversion from MARC record to Wikibase::Datatype::Item which is |
263
|
|
|
|
|
|
|
possible to load to Wikidata. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Returns Wikibase::Datatype instance. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 ERRORS |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
new(): |
270
|
|
|
|
|
|
|
From Class::Utils::set_params(): |
271
|
|
|
|
|
|
|
Unknown parameter '%s'. |
272
|
|
|
|
|
|
|
Parameter 'marc_record' is required. |
273
|
|
|
|
|
|
|
Parameter 'marc_record' must be a MARC::Record object. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
type(): |
276
|
|
|
|
|
|
|
Unsupported item with leader '%s'. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
wikidata(): |
279
|
|
|
|
|
|
|
Item '%s' doesn't supported. |
280
|
|
|
|
|
|
|
Unsupported item with leader '%s'. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 EXAMPLE |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=for comment filename=get_random_day.pl |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
use strict; |
287
|
|
|
|
|
|
|
use warnings; |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
use File::Temp; |
290
|
|
|
|
|
|
|
use MARC::Convert::Wikidata; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# Object. |
293
|
|
|
|
|
|
|
my $obj = MARC::Convert::Wikidata->new; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# TODO |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
# Output like: |
298
|
|
|
|
|
|
|
# TODO |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
L<Class::Utils>, |
303
|
|
|
|
|
|
|
L<Error::Pure>, |
304
|
|
|
|
|
|
|
L<MARC::Convert::Wikidata::Item::AudioBook>, |
305
|
|
|
|
|
|
|
L<MARC::Convert::Wikidata::Item::BookEdition>, |
306
|
|
|
|
|
|
|
L<MARC::Convert::Wikidata::Item::Periodical>, |
307
|
|
|
|
|
|
|
L<MARC::Convert::Wikidata::Transform>, |
308
|
|
|
|
|
|
|
L<Scalar::Util>. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 SEE ALSO |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=over |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=item L<MARC::Record> |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Perl extension for handling MARC records |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Item> |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Wikibase item datatype. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=back |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head1 REPOSITORY |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/MARC-Convert-Wikidata> |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head1 AUTHOR |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
L<http://skim.cz> |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
© 2021-2023 Michal Josef Špaček |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
BSD 2-Clause License |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head1 VERSION |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
0.01 |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=cut |