View | Details | Raw Unified | Return to bug 37196
Collapse All | Expand All

(-)a/C4/XSLT.pm (-1 / +1 lines)
Lines 191-197 sub XSLTParse4Display { Link Here
191
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
191
    my $frameworkcode = GetFrameworkCode($biblionumber) || '';
192
    my $record_processor = Koha::RecordProcessor->new(
192
    my $record_processor = Koha::RecordProcessor->new(
193
        {
193
        {
194
            filters => [ 'ExpandCodedFields' ],
194
            filters => [ 'ExpandCodedFields', 'Punctuation' ],
195
            options => {
195
            options => {
196
                interface     => $interface,
196
                interface     => $interface,
197
                frameworkcode => $frameworkcode
197
                frameworkcode => $frameworkcode
(-)a/Koha/Filter/MARC/Punctuation.pm (-1 / +158 lines)
Line 0 Link Here
0
- 
1
package Koha::Filter::MARC::Punctuation;
2
3
# Copyright 2024 join2
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
Koha::Filter::MARC::Punctuation - Automatically add punctuation to
23
Marc records if the leader specifies they were catalogued without it.
24
25
Documentation for proper punctuation:
26
https://www.loc.gov/aba/pcc/documents/isbdmarc2016.pdf
27
28
=head1 SYNOPSIS
29
30
31
=head1 DESCRIPTION
32
33
If the Marc leader 18 specifies, that the record was catalogued
34
without punctuation add the proper punctuation chars to the individual
35
fields before passing the record on to fruther processing. Once this
36
filter is applied it should be safe for further steps to assume that
37
the record holds Marc punctuation. (The records in the database are
38
_not_ changed.)
39
40
Trigger to add punctuation: leader 18 is either `n` or `c`.
41
42
Currently handled fields:
43
44
- 245
45
- 246
46
- 247
47
48
=cut
49
50
use strict;
51
use warnings;
52
53
use base qw(Koha::RecordProcessor::Base);
54
our $NAME = 'Punctuation';
55
56
=head2 filter
57
58
    my $newrecord = $filter->filter($record);
59
60
Return title fiels with proper punctuation either as the record held
61
them already or as they were added.
62
63
=cut
64
sub filter {
65
    my ( $self, $record ) = @_;
66
67
    return
68
        unless $record and ref($record) eq 'MARC::Record';
69
70
    my $leader = $record->leader();
71
    my $punctuation_omitted = (substr($leader, 18, 1) eq 'c') or
72
                              (substr($leader, 18, 1) eq 'n');
73
74
    if ($punctuation_omitted) {
75
        foreach my $field ( $record->fields ) {
76
            if ($field->tag() eq "245") {
77
78
                # simple chars _preceeding_ a subfield
79
                my %pchrs = (
80
                    'b' => ' : ',
81
                    'c' => ' / ',
82
                    'd' => ' ; ',
83
                    'e' => '. ',
84
                    'f' => ', ',
85
                    'g' => ', ',
86
                    'k' => ' : ',
87
                    'n' => '. ',
88
                    'p' => ', ',
89
                    's' => '. ',
90
                );
91
92
                my $i = 0;
93
                foreach my $subfield ( $field->subfields ) {
94
                    my $key   = $subfield->[0];
95
                    my $value = $subfield->[1];
96
97
                    if ( exists $pchrs{$key} ) {
98
                        $value = $pchrs{$key} . $value;
99
                    }
100
101
                    # media type needs to be enclosed
102
                    if ($key eq 'h') {
103
                        $value = '[' . $value . ']';
104
                    }
105
106
                    $field->add_subfields( $key => $value );    # add subfield to the end of the subfield list
107
                    $field->delete_subfield( pos => 0 );        # delete the subfield at the top of the subfield list
108
                    $i++;
109
110
                    # TBD does titles always end with a `.`?
111
                }
112
            }
113
            if (($field->tag() eq "246") or
114
                ($field->tag() eq "247")) {
115
                my %pchrs = (
116
                    'b' => ' : ',
117
                    'f' => ', ',
118
                    'n' => '. ',
119
                    'q' => ', ',
120
                    'r' => ' = ',
121
                    't' => ' = ',
122
                );
123
124
                my $i = 0;
125
                foreach my $subfield ( $field->subfields ) {
126
                    my $key   = $subfield->[0];
127
                    my $value = $subfield->[1];
128
129
                    if ( exists $pchrs{$key} ) {
130
                        $value = $pchrs{$key} . $value;
131
                    }
132
133
                    if ($key eq 'i') {
134
                        # _append_ a char to i
135
                        $value .= ': ';
136
                    }
137
                    if ($key eq 'g') {
138
                        $value = '(' . $value . ')';
139
                    }
140
                    # media type needs to be enclosed
141
                    if ($key eq 'h') {
142
                        $value = '[' . $value . ']';
143
                    }
144
145
                    $field->add_subfields( $key => $value );    # add subfield to the end of the subfield list
146
                    $field->delete_subfield( pos => 0 );        # delete the subfield at the top of the subfield list
147
                    $i++;
148
149
                    # TBD does titles always end with a `.`?
150
                }
151
            }
152
        }
153
   }
154
155
    return $record;
156
}
157
158
1;

Return to bug 37196