--- trunk/lib/WebPAC/Normalize.pm 2007/11/06 20:26:31 1011 +++ trunk/lib/WebPAC/Normalize.pm 2007/11/10 11:11:16 1021 @@ -13,9 +13,10 @@ marc_compose marc_leader marc_fixed marc_duplicate marc_remove marc_count marc_original_order + marc_template rec1 rec2 rec - frec + frec frec_eq frec_ne regex prefix suffix surround first lookup join_with save_into_lookup @@ -38,16 +39,20 @@ # debugging warn(s) my $debug = 0; +# FIXME use WebPAC::Normalize::ISBN; push @EXPORT, ( 'isbn_10', 'isbn_13' ); +use WebPAC::Normalize::MARC; +push @EXPORT, ( 'marc_template' ); + =head1 NAME WebPAC::Normalize - describe normalisaton rules using sets =cut -our $VERSION = '0.32'; +our $VERSION = '0.35'; =head1 SYNOPSIS @@ -133,6 +138,14 @@ $rec = shift or die "no record hash"; } +=head2 + + my $rec = _get_rec(); + +=cut + +sub _get_rec { $rec }; + =head2 _set_config Set current config hash @@ -814,7 +827,7 @@ return unless defined($rec->{$from}); my $r = $rec->{$from}; - die "record field $from isn't array\n" unless (ref($r) eq 'ARRAY'); + die "record field $from isn't array ",dump( $rec ) unless (ref($r) eq 'ARRAY'); my ($i1,$i2) = defined($marc_indicators->{$to}) ? @{ $marc_indicators->{$to} } : (' ',' '); warn "## marc_original_order($to,$from) source = ", dump( $r ),$/ if ($debug > 1); @@ -859,6 +872,7 @@ warn "## marc_record = ", dump( $marc_record ),$/ if ($debug > 1); } + =head2 marc_count Return number of MARC records created using L. @@ -871,6 +885,17 @@ return $#{ $marc_record }; } +=head2 _marc_push + + _marc_push( $marc ); + +=cut + +sub _marc_push { + my $marc = shift || die "no marc?"; + push @{ $marc_record->[ $marc_record_offset ] }, $marc; +} + =head1 Functions to extract data from input @@ -1000,12 +1025,6 @@ =cut -sub frec { - my @out = rec(@_); - warn "rec(",dump(@_),") has more than one return value, ignoring\n" if $#out > 0; - return shift @out; -} - sub rec { my @out; if ($#_ == 0) { @@ -1022,6 +1041,54 @@ } } +=head2 frec + +Returns first value from field + + $v = frec('200'); + $v = frec('200','a'); + +=cut + +sub frec { + my @out = rec(@_); + warn "rec(",dump(@_),") has more than one return value, ignoring\n" if $#out > 0; + return shift @out; +} + +=head2 frec_eq + +=head2 frec_ne + +Check if first values from two fields are same or different + + if ( frec_eq( 900 => 'a', 910 => 'c' ) ) { + # values are same + } else { + # values are different + } + +Strictly speaking C and C wouldn't be needed if you +could write something like: + + if ( frec( '900','a' ) eq frec( '910','c' ) ) { + # yada tada + } + +but you can't since our parser L will remove all whitespaces +in order to parse text and create invalid function C. + +=cut + +sub frec_eq { + my ( $f1,$sf1, $f2, $sf2 ) = @_; + return (rec( $f1, $sf1 ))[0] eq (rec( $f2, $sf2 ))[0]; +} + +sub frec_ne { + return ! frec_eq( @_ ); +} + =head2 regex Apply regex to some or all values