Last active
January 24, 2018 04:56
-
-
Save pabloab/44ce2d71ece4352517431db3034a11ca to your computer and use it in GitHub Desktop.
[Tamil to MRC format] Convert Koha::Contrib::Tamil koha-auth TXT to MRC format #Koha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Modern::Perl; | |
use MARC::Record; | |
@ARGV == 2 or die "usage: $0 auths.txt auths.mrc\n"; | |
my $inf = shift(); | |
my $ouf = shift(); | |
# http://STAFF_SITE/cgi-bin/koha/admin/authtypes.pl | |
my %code = ( | |
'PERSO_NAME' => '100', | |
'CORPO_NAME' => '110', | |
'MEETI_NAME' => '111', | |
'CHRON_TERM' => '148', | |
'GENRE/FORM' => '155', | |
'GEOGR_NAME' => '151', | |
'UNIF_TITLE' => '130', | |
'TOPIC_TERM' => '150', | |
); | |
# Perso:100, ind1=1; Corpo:110 ; Topic:150 | |
open my $out, ">", $ouf; | |
binmode(STDOUT, ":utf8"); | |
binmode($out, ":utf8"); | |
my $cont; | |
open my $file, "<:utf8", $inf or die("Can't open auth file!"); | |
while ( my $line = <$file> ) { | |
chomp $line; | |
$cont++; | |
my ($authcode, $sub) = $line =~ /(\w+)\t(.*)/; | |
my (@subfields) = split /\t|\|/, $sub; | |
if ( $#subfields < 1 ) { next; } | |
my $authtag = $code{$authcode}; | |
my $record = MARC::Record->new(); | |
my $leader = $record->leader(); | |
substr($leader, 5, 3) = 'naa'; | |
substr($leader, 6, 1) = 'z'; # z = Authority data (All authority records contain code z in Leader/06) | |
substr($leader, 9, 1) = 'a'; # encoding UTF-8 | |
$record->encoding( 'UTF-8' ); | |
$record->leader($leader); | |
my $field = MARC::Field->new($authtag, '', '', @subfields); | |
$record->append_fields( $field ); | |
# my $field = MARC::Field->new('942', '', '', ('a',$authcode)); | |
$record->append_fields( MARC::Field->new('942', '', '', ('a',$authcode)) ); | |
print "$cont: $authcode: " . $field->as_formatted() . "\n" ; | |
print $out $record->as_usmarc(); | |
# 008/#, why say o by default 0 http://www.loc.gov/marc/authority/ad008.html | |
# MARCAuthorityControlField008 | |
} | |
close $file; | |
close $out; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment