Skip to content

Commit

Permalink
Fix DDC conversion of notations like 869:3 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Feb 7, 2023
1 parent afa292a commit 2ceadd6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ddc/ddc2jskos
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
if [[ "$1" =~ ^ddc23[a-z][a-z](-.+)?.xml$ ]]; then
set -x
catmandu convert marcxml to ndjson \
catmandu convert -I lib marcxml to ndjson \
--fix "add_field(language,${1:5:2})" --fix ddc2jskos.fix \
< $1 > ${1/.xml/.ndjson}
else
Expand Down
4 changes: 3 additions & 1 deletion ddc/ddc2jskos.fix
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
select marc_match(LDR/6, 'w') # record type == classification
select marc_match(008/8, 'a') # valid records only

# some transformation in lib/Catmandu/Fix/ddc.pm
ddc()

# notation and uri
marc_map(153$ac, uri, join:'-')
replace_all(uri,'([^-]+)-([^-]+)-(.+)','$1-$2:$3')
if marc_has(153$z[0])
# table record
marc_spec(153$z[0],table)
Expand Down
30 changes: 30 additions & 0 deletions ddc/lib/Catmandu/Fix/ddc.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Catmandu::Fix::ddc;

use v5.14.1;
use Moo;

use Data::Dumper;

sub fix {
my ( $self, $data ) = @_;
my @fields = @{ $data->{record} };
my ($f153) = grep { $_->[0] eq '153' } @fields;
if ($f153) {
my $uri;
my @sf = splice @$f153, 3;
while (@sf) {
my $code = shift @sf;
my $value = shift @sf;
if ( $code eq 'a' ) {
$uri = defined $uri ? "$uri:$value" : $value;
}
elsif ( $code eq 'c' ) {
$uri .= "-$value";
}
}
$data->{uri} = $uri;
}
$data;
}

1;

0 comments on commit 2ceadd6

Please sign in to comment.