From 126681c4c1cd50870711bed210e19fb054740411 Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 2 Sep 2004 16:34:04 +0000 Subject: [PATCH] little tool to analyse the marc parameters. run without arguments to know what it does. export PERL5LIB (& export KOHA_CONF if not /etc/koha.conf) as usual --- misc/compare_iso_and_marc_parameters.pl | 92 +++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 misc/compare_iso_and_marc_parameters.pl diff --git a/misc/compare_iso_and_marc_parameters.pl b/misc/compare_iso_and_marc_parameters.pl new file mode 100755 index 0000000000..46a12a1f16 --- /dev/null +++ b/misc/compare_iso_and_marc_parameters.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl +# small script that dumps an iso2709 file. + + +use strict; + +# Koha modules used +use C4::Context; +use MARC::File::USMARC; +use MARC::Record; +use MARC::Batch; + +use Getopt::Long; +my ( $input_marc_file,$number,$nowarning,$frameworkcode) = ('',0); +my $version; +GetOptions( + 'file:s' => \$input_marc_file, + 'n:s' => \$number, + 'v' => \$version, + 'w' => \$nowarning, + 'c' => \$frameworkcode, +); + +$frameworkcode="" unless $frameworkcode; + +if ($version || ($input_marc_file eq '')) { + print <new( 'USMARC', $input_marc_file ); +$batch->warnings_off() unless $nowarning; +$batch->strict_off() unless $nowarning; +my $dbh=C4::Context->dbh; +my $sth = $dbh->prepare("select tagfield,tagsubfield,tab from marc_subfield_structure where frameworkcode=?"); +$sth->execute($frameworkcode); + +my %hash_unused; +my %hash_used; +while (my ($tagfield,$tagsubfield,$tab) = $sth->fetchrow) { + $hash_unused{"$tagfield$tagsubfield"} = 1 if ($tab eq -1); + $hash_used{"$tagfield$tagsubfield"} = 1 if ($tab ne -1); +} +my $i=0; +while ( my $record = $batch->next() ) { + $i++; + foreach my $MARCfield ($record->fields()) { + next if $MARCfield->tag()<=010; + if ($MARCfield) { + foreach my $fields ($MARCfield->subfields()) { + if ($fields) { + if ($hash_unused{$MARCfield->tag().@$fields[0]}>=1) { + $hash_unused{$MARCfield->tag().@$fields[0]}++; + } + if ($hash_used{$MARCfield->tag().@$fields[0]}>=1) { + $hash_used{$MARCfield->tag().@$fields[0]}++; + } + } + # foreach my $field (@$fields) { + # warn "==>".$MARCfield->tag().@$fields[0]; + # } + } + } + } +} +print "Undeclared tag/subfields that exists in the file\n"; +print "================================================\n"; +foreach my $key (sort keys %hash_unused) { + print "$key => ".($hash_unused{$key}-1)."\n" unless ($hash_unused{$key}==1); +} + +print "Declared tag/subfields unused in the iso2709 file\n"; +print "=================================================\n"; +foreach my $key (sort keys %hash_used) { + print "$key => ".($hash_used{$key}-1)."\n" if ($hash_used{$key}==1); +} + +# foreach my $x (sort keys %resB) { +# print "$x => ".$resB{$x}."\n"; +# } +print "\n==================\n$i record parsed\n"; -- 2.39.5