line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: sw=4 |
2
|
|
|
|
|
|
|
package MARC::Loader; |
3
|
1
|
|
|
1
|
|
59551
|
use 5.10.0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
7
|
1
|
|
|
1
|
|
953
|
use MARC::Record; |
|
1
|
|
|
|
|
8227
|
|
|
1
|
|
|
|
|
43
|
|
8
|
1
|
|
|
1
|
|
8
|
use YAML; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
9
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw< reftype >; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1612
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.004001'; |
11
|
|
|
|
|
|
|
our $DEBUG = 0; |
12
|
0
|
0
|
|
0
|
0
|
0
|
sub debug { $DEBUG and say STDERR @_ } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
95
|
my ($self,$data) = @_; |
16
|
1
|
|
|
|
|
8
|
my $r = MARC::Record->new(); |
17
|
1
|
|
|
|
|
10
|
my $orderfields = 0; |
18
|
1
|
|
|
|
|
1
|
my $ordersubfields = 0; |
19
|
1
|
|
|
|
|
1
|
my $cleannsb = 0; |
20
|
1
|
|
|
|
|
12
|
my $lc={};#the controlfield's list |
21
|
1
|
|
|
|
|
2
|
my $lf={};#the field's list |
22
|
1
|
|
|
|
|
1
|
my $cf={};#counter where multiple fields with same name |
23
|
1
|
|
|
|
|
2
|
my $bf={};#bool ok if field have one subfield at least |
24
|
1
|
50
|
33
|
|
|
7
|
if (defined($$data{"ldr"}) and $$data{"ldr"} ne "") { |
25
|
1
|
|
|
|
|
6
|
$r->leader($$data{"ldr"}); |
26
|
|
|
|
|
|
|
} |
27
|
1
|
50
|
|
|
|
22
|
if ($$data{"orderfields"}) { |
28
|
0
|
|
|
|
|
0
|
$orderfields=1; |
29
|
|
|
|
|
|
|
} |
30
|
1
|
50
|
|
|
|
4
|
if ($$data{"ordersubfields"}) { |
31
|
0
|
|
|
|
|
0
|
$ordersubfields=1; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
50
|
|
|
|
3
|
if ($$data{"cleannsb"}) { |
34
|
1
|
|
|
|
|
2
|
$cleannsb=1; |
35
|
|
|
|
|
|
|
} |
36
|
1
|
|
|
|
|
16
|
foreach my $k ( sort {$a cmp $b} keys(%$data) ) { |
|
124
|
|
|
|
|
105
|
|
37
|
32
|
100
|
100
|
|
|
227
|
if (($k eq "ldr") or ($k eq "orderfields") or ($k eq "ordersubfields") or ($k eq "cleannsb")) { |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
38
|
4
|
|
|
|
|
13
|
next; |
39
|
|
|
|
|
|
|
} |
40
|
28
|
100
|
|
|
|
57
|
if ( ref( $$data{$k} ) eq "ARRAY" ) { |
41
|
16
|
|
|
|
|
16
|
foreach my $v ( sort {$a cmp $b} @{$$data{$k}} ) { |
|
21
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
36
|
|
42
|
30
|
|
|
|
|
48
|
createfield($k,$lc,$lf,$bf,$cf,$v,$cleannsb); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} else { |
45
|
12
|
|
|
|
|
25
|
createfield($k,$lc,$lf,$bf,$cf,$$data{$k},$cleannsb); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
5
|
foreach my $contk ( sort {$a cmp $b} keys(%$lc) ) { |
|
3
|
|
|
|
|
4
|
|
49
|
3
|
50
|
|
|
|
26
|
if($orderfields) { |
50
|
0
|
|
|
|
|
0
|
$r->insert_fields_ordered( $$lc{$contk} ); |
51
|
|
|
|
|
|
|
} else { |
52
|
3
|
|
|
|
|
8
|
$r->append_fields( $$lc{$contk} ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
13
|
foreach my $k ( sort {$a cmp $b} keys(%$lf) ) { |
|
77
|
|
|
|
|
59
|
|
56
|
22
|
50
|
|
|
|
217
|
if ($$bf{$k}==1) { |
57
|
22
|
|
|
|
|
56
|
$$lf{$k}->delete_subfield(pos => 0); |
58
|
22
|
50
|
|
|
|
1108
|
if($orderfields) { |
59
|
0
|
|
|
|
|
0
|
$r->insert_fields_ordered( $$lf{$k} ); |
60
|
|
|
|
|
|
|
} else { |
61
|
22
|
|
|
|
|
54
|
$r->append_fields( $$lf{$k} ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
24
|
$r; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub createfield { |
69
|
42
|
|
|
42
|
0
|
58
|
my ($k,$lc,$lf,$bf,$cf,$v,$cleannsb) = @_; |
70
|
|
|
|
|
|
|
#$k = the hash key that defines the field or subfield name |
71
|
|
|
|
|
|
|
#$v = the field or subfield value |
72
|
|
|
|
|
|
|
#$lc= the controlfield's list |
73
|
|
|
|
|
|
|
#$lf= the field's list |
74
|
|
|
|
|
|
|
#$cf= counter where multiple fields with same name |
75
|
|
|
|
|
|
|
#$bf= bool ok if field have one subfield at least |
76
|
42
|
|
|
|
|
43
|
my $prefield=""; |
77
|
42
|
100
|
33
|
|
|
193
|
if ($k=~/^((.*)##)?(\D)(\d{3})(\w)$/) { |
|
|
50
|
|
|
|
|
|
78
|
25
|
50
|
|
|
|
45
|
$prefield=$1 if $1; |
79
|
25
|
100
|
|
|
|
51
|
if (!exists($$lf{$prefield.$4})) { |
80
|
8
|
100
|
66
|
|
|
44
|
if($4<10 and defined($v) and $v ne "") { |
|
|
|
66
|
|
|
|
|
81
|
1
|
50
|
|
|
|
7
|
$v=nsbclean($v) if $cleannsb; |
82
|
1
|
|
|
|
|
5
|
$$lc{$prefield.$4} = MARC::Field->new( "$4", $v ); |
83
|
|
|
|
|
|
|
} else { |
84
|
7
|
|
|
|
|
22
|
$$lf{$prefield.$4} = MARC::Field->new( "$4", "", "", 0 => "temp" ); |
85
|
|
|
|
|
|
|
#$fnoauth = MARC::Field->new( '009', $noauth ); |
86
|
7
|
|
|
|
|
274
|
$$bf{$prefield.$4}=0; |
87
|
7
|
50
|
33
|
|
|
30
|
if (defined($v) and $v ne "") { |
88
|
7
|
50
|
|
|
|
15
|
$v=nsbclean($v) if $cleannsb; |
89
|
7
|
|
|
|
|
21
|
createsubfield($$lf{$prefield.$4},$5,$v,$k); |
90
|
7
|
|
|
|
|
68
|
$$bf{$prefield.$4}=1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} else { |
94
|
17
|
100
|
66
|
|
|
65
|
if (defined($v) and $v ne "") { |
95
|
16
|
50
|
|
|
|
31
|
$v=nsbclean($v) if $cleannsb; |
96
|
16
|
|
|
|
|
42
|
createsubfield($$lf{$prefield.$4},$5,$v,$k); |
97
|
16
|
|
|
|
|
170
|
$$bf{$prefield.$4}=1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} elsif (($k=~/^((.*)##)?(\D)(\d{3})$/) and ( ref( $v ) eq "HASH" )) { |
101
|
17
|
100
|
|
|
|
39
|
$prefield=$1 if $1; |
102
|
17
|
100
|
|
|
|
41
|
if (!exists($$cf{$prefield.$4})) { |
103
|
9
|
|
|
|
|
19
|
$$cf{$prefield.$4}=0; |
104
|
|
|
|
|
|
|
} |
105
|
17
|
|
|
|
|
25
|
$$cf{$prefield.$4}++; |
106
|
17
|
100
|
|
|
|
34
|
if($4<10){ |
107
|
2
|
|
|
|
|
7
|
foreach my $k ( sort {$a cmp $b} keys(%$v) ) { |
|
0
|
|
|
|
|
0
|
|
108
|
2
|
50
|
33
|
|
|
10
|
if (defined($$v{$k}) and $$v{$k} ne "") { |
109
|
2
|
50
|
|
|
|
10
|
if ($k=~/^((.*)##)?(\D)(\d{3})(\w)$/) { |
110
|
2
|
50
|
|
|
|
9
|
$$v{$k}=nsbclean($$v{$k}) if $cleannsb; |
111
|
2
|
|
|
|
|
12
|
$$lc{$prefield.$4.$$cf{$prefield.$4}} = MARC::Field->new( "$4", $$v{$k} ); |
112
|
2
|
|
|
|
|
65
|
$$bf{$prefield.$4.$$cf{$prefield.$4}}=1; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
0
|
warn "wrong field name : $k";return; |
|
0
|
|
|
|
|
0
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else |
120
|
|
|
|
|
|
|
{ |
121
|
15
|
|
|
|
|
79
|
$$lf{$prefield.$4.$$cf{$prefield.$4}} = MARC::Field->new( "$4", "", "", 0 => "temp" ); |
122
|
15
|
|
|
|
|
636
|
$$bf{$prefield.$4.$$cf{$prefield.$4}}=0; |
123
|
15
|
|
|
|
|
53
|
foreach my $k ( sort {$a cmp $b} keys(%$v) ) { |
|
55
|
|
|
|
|
55
|
|
124
|
46
|
100
|
66
|
|
|
384
|
if (defined($$v{$k}) and $$v{$k} ne "" and ref($$v{$k}) eq "ARRAY" ) { |
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
125
|
1
|
|
|
|
|
2
|
foreach my $v ( sort {$a cmp $b} @{$$v{$k}} ) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
126
|
2
|
50
|
|
|
|
7
|
if ($k=~/^((.*)##)?(\D)(\d{3})(\w)$/) { |
127
|
2
|
50
|
|
|
|
6
|
$v=nsbclean($v) if $cleannsb; |
128
|
2
|
|
|
|
|
9
|
createsubfield($$lf{$prefield.$4.$$cf{$prefield.$4}},$5,$v,$k); |
129
|
2
|
|
|
|
|
20
|
$$bf{$prefield.$4.$$cf{$prefield.$4}}=1; |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
0
|
warn "wrong field name : $k";return; |
|
0
|
|
|
|
|
0
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} elsif (defined($$v{$k}) and $$v{$k} ne "") { |
135
|
43
|
50
|
|
|
|
142
|
if ($k=~/^((.*)##)?(\D)(\d{3})(\w)$/) { |
136
|
43
|
50
|
|
|
|
192
|
$$v{$k}=nsbclean($$v{$k}) if $cleannsb; |
137
|
43
|
|
|
|
|
151
|
createsubfield($$lf{$prefield.$4.$$cf{$prefield.$4}},$5,$$v{$k},$k); |
138
|
43
|
|
|
|
|
481
|
$$bf{$prefield.$4.$$cf{$prefield.$4}}=1; |
139
|
|
|
|
|
|
|
} else { |
140
|
0
|
|
|
|
|
0
|
warn "wrong field name : $k";return; |
|
0
|
|
|
|
|
0
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} else { |
146
|
0
|
|
|
|
|
0
|
warn "wrong field name : $k";return; |
|
0
|
|
|
|
|
0
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub createsubfield { |
151
|
68
|
|
|
68
|
0
|
119
|
my ($f,$s,$v,$k)=@_; |
152
|
|
|
|
|
|
|
#$f = the field |
153
|
|
|
|
|
|
|
#$s = the subfield name |
154
|
|
|
|
|
|
|
#$k = the hash key that defines the subfield name |
155
|
|
|
|
|
|
|
#$v = the subfield value |
156
|
68
|
100
|
|
|
|
118
|
if ($k=~/^((.*)##)?(i)(\d{3})(\w)$/) { |
157
|
4
|
|
|
|
|
7
|
my $ind=$5; |
158
|
4
|
50
|
33
|
|
|
28
|
if ( ($5=~/1|2/) and ($v=~/\d|\|/) ) { |
159
|
4
|
|
|
|
|
14
|
$f->update( "ind$ind" => $v); |
160
|
|
|
|
|
|
|
} else { |
161
|
0
|
|
|
|
|
0
|
warn "wrong ind values : $k=$v";return; |
|
0
|
|
|
|
|
0
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} else { |
164
|
64
|
|
|
|
|
172
|
$f->add_subfields( "$s" => $v ); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub nsbclean { |
169
|
71
|
|
|
71
|
0
|
76
|
my ($string) = @_ ; |
170
|
71
|
|
|
|
|
65
|
$_ = $string ; |
171
|
71
|
|
|
|
|
73
|
s/\x88//g ;# NSB : begin Non Sorting Block |
172
|
71
|
|
|
|
|
66
|
s/\x89//g ;# NSE : Non Sorting Block end |
173
|
71
|
|
|
|
|
60
|
s/\x98//g ;# NSB : begin Non Sorting Block |
174
|
71
|
|
|
|
|
65
|
s/\x9C//g ;# NSE : Non Sorting Block end |
175
|
71
|
|
|
|
|
66
|
s/\xC2//g ;# What is this char ? It is sometimes left by the regexp after removing NSB / NSE |
176
|
71
|
|
|
|
|
57
|
$string = $_ ; |
177
|
71
|
|
|
|
|
113
|
return($string) ; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
1; |
180
|
|
|
|
|
|
|
__END__ |