X-Git-Url: http://git.rot13.org/?p=crolist2marc;a=blobdiff_plain;f=crolist2marc.pl;h=39eb02885cb43f6a7ead227c9586fa1e18523c0a;hp=fdb5402346a49801aebf2847c9708c4dcb044e5d;hb=aa91fb3e8dfa676159100b20c0374cca84ccd886;hpb=a0984ce9f4c0a38990f46cd54976a94dbb0a3376 diff --git a/crolist2marc.pl b/crolist2marc.pl index fdb5402..39eb028 100755 --- a/crolist2marc.pl +++ b/crolist2marc.pl @@ -23,7 +23,7 @@ sub csv_file { $lines++; if ( ! $text ) { - print STDERR "\nSKIP $file +$lines [$_] "; + print STDERR "\nSKIP $file +$lines [$_] " if $idsl; next; } @@ -48,29 +48,56 @@ sub csv_file { print STDERR "\n"; } -csv_file( 'TEKTAG.csv', sub { +csv_file( 'tsv/TEKTAG.csv', sub { my $line = shift; - my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $textkey, $textres ) = split(/,/,$_); + my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $textkey, $textres ) = split(/\t/,$_); my $text = $textkey . $textres; # FIXME fix CAPITAL letters in $textkey return ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $text ); }); -csv_file( 'LONTAG.csv', sub { +csv_file( 'tsv/LONTAG.csv', sub { my $line = shift; - my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $text ) = split(/;/,$_, 7); + my ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $text ) = split(/\t/,$_, 7); - $text =~ s/;+$//; - $text =~ s/;/\n/g; # join OPIS[1-11] + $text =~ s/\t+$//; + $text =~ s/\t/\n/g; # join OPIS[1-11] return ( $idsl, $tag, $tagno, $id, $sfi, $sfino, $text ); }); +csv_file( 'tsv/IDNTAG.csv', sub { + my $line = shift; + + my ( $idsl, $tag, $STSL, $KZVS, $BIBRAZ, $HIRAZ, $KPS, $OKO ) = split(/\t/,$_); + + my @leader; + $leader[5] = $STSL; + $leader[6] = $KZVS; + $leader[7] = $BIBRAZ; + $leader[8] = $HIRAZ; + $leader[17] = $KPS; + $leader[18] = $OKO; + + $leader[23] = ' '; # last char; + + my $full = join('', map { defined $_ ? $_ : ' ' } @leader); + $data->{$idsl}->{'leader'} = $full; + return; +}); + +csv_file( 'tsv/OBRTAG.csv', sub { + my $line = shift; + + my ( $IDSL, $TAG, $TAGNO, $ID, $SFI, $SFINO, $CODINF ) = split(/\t/,$_); + return ( $IDSL, $TAG, $TAGNO, $ID, $SFI, $SFINO, $CODINF ); +}); + print STDERR "\n# getting all ids "; -my @ids = keys %$data; +my @ids = sort keys %$data; print STDERR scalar(@ids), " found\n"; my $marc_file = 'liberated.marc'; @@ -80,12 +107,19 @@ my $number = 0; foreach my $id ( @ids ) { my $rec = MARC::Record->new; $rec->encoding( 'UTF-8' ); + $rec->add_fields( [ '001', $id ] ); + foreach my $field ( sort keys %{ $data->{$id} } ) { + if ( $field eq 'leader' ) { + $rec->leader( $data->{$id}->{$field} ); + next; + } foreach my $arr ( @{ $data->{$id}->{$field} } ) { if ( ! $arr ) { - print STDERR "SKIPPED $id $field ",dump( $data->{$id} ); +# print STDERR "SKIPPED $id $field ",dump( $data->{$id}->{$field} ), "\n"; next; } + $arr = [ $arr->[3] ] if ( $field < 010 ); # control fields don't have idicators or subfields $rec->add_fields( $field, @$arr ); } }