Translation updates for Koha 16.05.00 release
[koha.git] / C4 / Heading / MARC21.pm
blob9a50cf6c28448083701fed4ef66f1a2fb4db195b
1 package C4::Heading::MARC21;
3 # Copyright (C) 2008 LibLime
5 # This file is part of Koha.
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.
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.
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>.
20 use strict;
21 use warnings;
22 use MARC::Record;
23 use MARC::Field;
26 =head1 NAME
28 C4::Heading::MARC21
30 =head1 SYNOPSIS
32 use C4::Heading::MARC21;
34 =head1 DESCRIPTION
36 This is an internal helper class used by
37 C<C4::Heading> to parse headings data from
38 MARC21 records. Object of this type
39 do not carry data, instead, they only
40 dispatch functions.
42 =head1 DATA STRUCTURES
44 FIXME - this should be moved to a configuration file.
46 =head2 bib_heading_fields
48 =cut
50 my $bib_heading_fields = {
51 '100' => {
52 auth_type => 'PERSO_NAME',
53 subfields => 'abcdfghjklmnopqrst',
54 main_entry => 1
56 '110' => {
57 auth_type => 'CORPO_NAME',
58 subfields => 'abcdfghklmnoprst',
59 main_entry => 1
61 '111' => {
62 auth_type => 'MEETI_NAME',
63 subfields => 'acdfghjklnpqst',
64 main_entry => 1
66 '130' => {
67 auth_type => 'UNIF_TITLE',
68 subfields => 'adfghklmnoprst',
69 main_entry => 1
71 '440' => { auth_type => 'UNIF_TITLE', subfields => 'anp', series => 1 },
72 '600' => {
73 auth_type => 'PERSO_NAME',
74 subfields => 'abcdfghjklmnopqrstvxyz',
75 subject => 1
77 '610' => {
78 auth_type => 'CORPO_NAME',
79 subfields => 'abcdfghklmnoprstvxyz',
80 subject => 1
82 '611' => {
83 auth_type => 'MEETI_NAME',
84 subfields => 'acdfghjklnpqstvxyz',
85 subject => 1
87 '630' => {
88 auth_type => 'UNIF_TITLE',
89 subfields => 'adfghklmnoprstvxyz',
90 subject => 1
92 '648' => { auth_type => 'CHRON_TERM', subfields => 'avxyz', subject => 1 },
93 '650' => { auth_type => 'TOPIC_TERM', subfields => 'abvxyz', subject => 1 },
94 '651' => { auth_type => 'GEOGR_NAME', subfields => 'avxyz', subject => 1 },
95 '655' => { auth_type => 'GENRE/FORM', subfields => 'avxyz', subject => 1 },
96 '690' => { auth_type => 'TOPIC_TERM', subfields => 'abvxyz', subject => 1 },
97 '691' => { auth_type => 'GEOGR_NAME', subfields => 'avxyz', subject => 1 },
98 '696' => { auth_type => 'PERSO_NAME', subfields => 'abcdfghjklmnopqrst' },
99 '697' => { auth_type => 'CORPO_NAME', subfields => 'abcdfghklmnoprst' },
100 '698' => { auth_type => 'MEETI_NAME', subfields => 'acdfghjklnpqst' },
101 '699' => { auth_type => 'UNIF_TITLE', subfields => 'adfghklmnoprst' },
102 '700' => { auth_type => 'PERSO_NAME', subfields => 'abcdfghjklmnopqrst' },
103 '710' => { auth_type => 'CORPO_NAME', subfields => 'abcdfghklmnoprst' },
104 '711' => { auth_type => 'MEETI_NAME', subfields => 'acdfghjklnpqst' },
105 '730' => { auth_type => 'UNIF_TITLE', subfields => 'adfghklmnoprst' },
106 '800' => {
107 auth_type => 'PERSO_NAME',
108 subfields => 'abcdfghjklmnopqrst',
109 series => 1
111 '810' => {
112 auth_type => 'CORPO_NAME',
113 subfields => 'abcdfghklmnoprst',
114 series => 1
116 '811' =>
117 { auth_type => 'MEETI_NAME', subfields => 'acdfghjklnpqst', series => 1 },
118 '830' =>
119 { auth_type => 'UNIF_TITLE', subfields => 'adfghklmnoprst', series => 1 },
122 =head2 subdivisions
124 =cut
126 my %subdivisions = (
127 'v' => 'formsubdiv',
128 'x' => 'generalsubdiv',
129 'y' => 'chronologicalsubdiv',
130 'z' => 'geographicsubdiv',
133 =head1 METHODS
135 =head2 new
137 my $marc_handler = C4::Heading::MARC21->new();
139 =cut
141 sub new {
142 my $class = shift;
143 return bless {}, $class;
146 =head2 valid_bib_heading_tag
148 =cut
150 sub valid_bib_heading_tag {
151 my $self = shift;
152 my $tag = shift;
153 my $frameworkcode = shift;
155 if ( exists $bib_heading_fields->{$tag} ) {
156 return 1;
158 else {
159 return 0;
164 =head2 parse_heading
166 =cut
168 sub parse_heading {
169 my $self = shift;
170 my $field = shift;
172 my $tag = $field->tag;
173 my $field_info = $bib_heading_fields->{$tag};
175 my $auth_type = $field_info->{'auth_type'};
176 my $thesaurus =
177 $tag =~ m/6../
178 ? _get_subject_thesaurus($field)
179 : "lcsh"; # use 'lcsh' for names, UT, etc.
180 my $search_heading =
181 _get_search_heading( $field, $field_info->{'subfields'} );
182 my $display_heading =
183 _get_display_heading( $field, $field_info->{'subfields'} );
185 return ( $auth_type, $thesaurus, $search_heading, $display_heading,
186 'exact' );
189 =head1 INTERNAL FUNCTIONS
191 =head2 _get_subject_thesaurus
193 =cut
195 sub _get_subject_thesaurus {
196 my $field = shift;
197 my $ind2 = $field->indicator(2);
199 my $thesaurus = "notdefined";
200 if ( $ind2 eq '0' ) {
201 $thesaurus = "lcsh";
203 elsif ( $ind2 eq '1' ) {
204 $thesaurus = "lcac";
206 elsif ( $ind2 eq '2' ) {
207 $thesaurus = "mesh";
209 elsif ( $ind2 eq '3' ) {
210 $thesaurus = "nal";
212 elsif ( $ind2 eq '4' ) {
213 $thesaurus = "notspecified";
215 elsif ( $ind2 eq '5' ) {
216 $thesaurus = "cash";
218 elsif ( $ind2 eq '6' ) {
219 $thesaurus = "rvm";
221 elsif ( $ind2 eq '7' ) {
222 my $sf2 = $field->subfield('2');
223 $thesaurus = $sf2 if defined($sf2);
226 return $thesaurus;
229 =head2 _get_search_heading
231 =cut
233 sub _get_search_heading {
234 my $field = shift;
235 my $subfields = shift;
237 my $heading = "";
238 my @subfields = $field->subfields();
239 my $first = 1;
240 for ( my $i = 0 ; $i <= $#subfields ; $i++ ) {
241 my $code = $subfields[$i]->[0];
242 my $code_re = quotemeta $code;
243 my $value = $subfields[$i]->[1];
244 $value =~ s/[-,.:=;!%\/]$//;
245 next unless $subfields =~ qr/$code_re/;
246 if ($first) {
247 $first = 0;
248 $heading = $value;
250 else {
251 if ( exists $subdivisions{$code} ) {
252 $heading .= " $subdivisions{$code} $value";
254 else {
255 $heading .= " $value";
260 # remove characters that are part of CCL syntax
261 $heading =~ s/[)(=]//g;
263 return $heading;
266 =head2 _get_display_heading
268 =cut
270 sub _get_display_heading {
271 my $field = shift;
272 my $subfields = shift;
274 my $heading = "";
275 my @subfields = $field->subfields();
276 my $first = 1;
277 for ( my $i = 0 ; $i <= $#subfields ; $i++ ) {
278 my $code = $subfields[$i]->[0];
279 my $code_re = quotemeta $code;
280 my $value = $subfields[$i]->[1];
281 next unless $subfields =~ qr/$code_re/;
282 if ($first) {
283 $first = 0;
284 $heading = $value;
286 else {
287 if ( exists $subdivisions{$code} ) {
288 $heading .= "--$value";
290 else {
291 $heading .= " $value";
295 return $heading;
298 # Additional limiters that we aren't using:
299 # if ($self->{'subject_added_entry'}) {
300 # $limiters .= " AND Heading-use-subject-added-entry=a";
302 # if ($self->{'series_added_entry'}) {
303 # $limiters .= " AND Heading-use-series-added-entry=a";
305 # if (not $self->{'subject_added_entry'} and not $self->{'series_added_entry'}) {
306 # $limiters .= " AND Heading-use-main-or-added-entry=a"
309 =head1 AUTHOR
311 Koha Development Team <http://koha-community.org/>
313 Galen Charlton <galen.charlton@liblime.com>
315 =cut