| 1 | package MARC::Moose::Formater::AuthorityUnimarcToMarc21; | ||||||||||||||
| 2 | 4 | $MARC::Moose::Formater::AuthorityUnimarcToMarc21::VERSION = '1.0.46'; | |||||||||||||
| 3 | # ABSTRACT: Convert authority record from UNIMARC to MARC21 | ||||||||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 4 | ▶ | use Modern::Perl; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 4 | extends 'MARC::Moose::Formater'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 4 | ▶ | use MARC::Moose::Field::Control; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 4 | ▶ | use MARC::Moose::Field::Std; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | |||||||||||||||
| 14 | |||||||||||||||
| 15 | # List of moved fields unchanged | ||||||||||||||
| 16 | 4 | my @unchanged; | |||||||||||||
| 17 | 4 | push @unchanged, [$_, 500] for 300..315; | |||||||||||||
| 18 | 4 | push @unchanged, [317, 561], | |||||||||||||
| 19 | [320, 504], | ||||||||||||||
| 20 | [321, 500], | ||||||||||||||
| 21 | [322, 508], | ||||||||||||||
| 22 | [323, 511], | ||||||||||||||
| 23 | [324, 500], | ||||||||||||||
| 24 | [328, 502], | ||||||||||||||
| 25 | [330, 520], | ||||||||||||||
| 26 | [332, 524], | ||||||||||||||
| 27 | [333, 521], | ||||||||||||||
| 28 | [337, 538], | ||||||||||||||
| 29 | [686, '084']; | ||||||||||||||
| 30 | |||||||||||||||
| 31 | # Tags with non-filing indicator (pos 1 or 2) | ||||||||||||||
| 32 | 4 | my $nonfiling_tags = [ | |||||||||||||
| 33 | [ qw/130 630 730 740 830/ ], | ||||||||||||||
| 34 | [ qw/240 242 243 245 440 830/ ], | ||||||||||||||
| 35 | ]; | ||||||||||||||
| 36 | |||||||||||||||
| 37 | # NSB/NSE characters | ||||||||||||||
| 38 | 4 | my $ns_characters = [ | |||||||||||||
| 39 | [ "\x08", "\x09" ], | ||||||||||||||
| 40 | [ "\x88", "\x89" ] | ||||||||||||||
| 41 | ]; | ||||||||||||||
| 42 | |||||||||||||||
| 43 | |||||||||||||||
| 44 | 4 | my $equivals = [ | |||||||||||||
| 45 | [ qw/ 200 100 / ], | ||||||||||||||
| 46 | [ qw/ 210 110 / ], | ||||||||||||||
| 47 | [ qw/ 215 151 / ], | ||||||||||||||
| 48 | [ qw/ 220 120 / ], | ||||||||||||||
| 49 | [ qw/ 225 125 / ], | ||||||||||||||
| 50 | [ qw/ 230 130 / ], | ||||||||||||||
| 51 | [ qw/ 240 140 / ], | ||||||||||||||
| 52 | [ qw/ 250 150 / ], | ||||||||||||||
| 53 | [ qw/ 415 451 / ], | ||||||||||||||
| 54 | [ qw/ 515 551 / ], | ||||||||||||||
| 55 | ]; | ||||||||||||||
| 56 | |||||||||||||||
| 57 | override 'format' => sub { | ||||||||||||||
| 58 | 0 | ▶ | my ($self, $unimarc) = @_; | ||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my $record = MARC::Moose::Record->new(); | |||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | $record->_leader(" nam a22 7a 4500"); | |||||||||||||
| 63 | |||||||||||||||
| 64 | # First, copy as it is | ||||||||||||||
| 65 | 0 | $record->append( grep { 1 } @{$unimarc->fields} ); | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | for (@$equivals) { | |||||||||||||
| 68 | 0 | my ($from, $to) = @$_; | |||||||||||||
| 69 | 0 | for my $field ($record->field($from)) { | |||||||||||||
| 70 | 0 | $field->tag($to); | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | # On intervertit $z et $y | ||||||||||||||
| 75 | 0 | for my $field ( $record->field('1..|4..|5..') ) { | |||||||||||||
| 76 | $field->subf( [ map { | ||||||||||||||
| 77 | 0 | my ($letter, $value) = @$_; | |||||||||||||
| 78 | 0 | ▶ | $letter = $letter eq 'y' ? 'z' : | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 79 | $letter eq 'z' ? 'y' : $letter; | ||||||||||||||
| 80 | 0 | [ $letter, $value ]; | |||||||||||||
| 81 | 0 | } @{$field->subf} ] ); | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | # Clean non-filing characters in all fields | ||||||||||||||
| 85 | 0 | for my $field (@{$record->fields}) { | |||||||||||||
| 86 | 0 | ▶ | next if $field->tag lt '010'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 0 | for (@{$field->subf} ) { | |||||||||||||
| 88 | 0 | ▶ | next if $_->[0] !~ /[a-z0-9]/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 0 | $_->[1] =~ s/\x08|\x09//g; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 0 | return $record; | |||||||||||||
| 94 | 4 | }; | |||||||||||||
| 95 | |||||||||||||||
| 96 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 4 | 1; | |||||||||||||
| 99 | |||||||||||||||
| 100 | __END__ | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =pod | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =encoding UTF-8 | ||||||||||||||
| 105 | |||||||||||||||
| 106 | =head1 NAME | ||||||||||||||
| 107 | |||||||||||||||
| 108 | MARC::Moose::Formater::AuthorityUnimarcToMarc21 - Convert authority record from UNIMARC to MARC21 | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head1 VERSION | ||||||||||||||
| 111 | |||||||||||||||
| 112 | version 1.0.46 | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =head1 SYNOPSYS | ||||||||||||||
| 115 | |||||||||||||||
| 116 | Read a authorities UNIMARC ISO2709 file and dump it to STDOUT in text | ||||||||||||||
| 117 | transformed into MARC21: | ||||||||||||||
| 118 | |||||||||||||||
| 119 | my $reader = MARC::Moose::Reader::File::Iso2709->new( | ||||||||||||||
| 120 | file => 'authority-unimarc.iso' ); | ||||||||||||||
| 121 | my $formater = MARC::Moose::Formater::AuthorityUnimarcToMarc21->new(); | ||||||||||||||
| 122 | while ( my $unimarc = $reader->read() ) { | ||||||||||||||
| 123 | my $marc21 = $formater->format($unimarc); | ||||||||||||||
| 124 | print $marc21->as('Text'); | ||||||||||||||
| 125 | } | ||||||||||||||
| 126 | |||||||||||||||
| 127 | Same with shortcut: | ||||||||||||||
| 128 | |||||||||||||||
| 129 | my $reader = MARC::Moose::Reader::File::Iso2709->new( | ||||||||||||||
| 130 | file => 'authority-unimarc.iso' ); | ||||||||||||||
| 131 | while ( my $unimarc = $reader->read() ) { | ||||||||||||||
| 132 | print $unimarc->as('AuthorityUnimarcToMarc21')->as('Text'); | ||||||||||||||
| 133 | } | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =head1 COMMAND LINE | ||||||||||||||
| 136 | |||||||||||||||
| 137 | If you don't want to write a Perl script, you can use the L<marcmoose> command. | ||||||||||||||
| 138 | This way, you can for example convert a ISO 2709 authorities UNIMARC file named | ||||||||||||||
| 139 | C<unimarc.iso> into a ISO 2709 MARC21 file named C<marc.iso>: | ||||||||||||||
| 140 | |||||||||||||||
| 141 | marcmoose --parser iso2709 --formater iso2709 --converter authorityunimarctomarc21 | ||||||||||||||
| 142 | --output marc.iso unimarc.iso | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =head1 AUTHOR | ||||||||||||||
| 145 | |||||||||||||||
| 146 | Frédéric Demians <f.demians@tamil.fr> | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 149 | |||||||||||||||
| 150 | This software is copyright (c) 2022 by Frédéric Demians. | ||||||||||||||
| 151 | |||||||||||||||
| 152 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 153 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 154 | |||||||||||||||
| 155 | =cut | ||||||||||||||