r732@llin: dpavlin | 2006-06-29 23:20:46 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 29 Jun 2006 21:19:08 +0000 (21:19 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 29 Jun 2006 21:19:08 +0000 (21:19 +0000)
 document magic (that is how WebPAC detects repeatable fields) and fix it to actually work :-)

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@543 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Normalize.pm

index 6d44f5d..b612301 100644 (file)
@@ -152,8 +152,16 @@ Get all fields defined by calls to C<marc21>
 
        $marc->add_fields( WebPAC::Normalize:_get_marc21_fields() );
 
-B<TODO>: implement exceptions to magic which unrolls repeated subfields
-as new field with that subfield.
+
+
+We are using I<magic> which detect repeatable fields only from
+sequence of field/subfield data generated by normalization.
+
+Repeatable field is created if there is second occurence of same subfield or
+if any of indicators are different. This is sane for most cases except for
+non-repeatable fields with repeatable subfields.
+
+B<TODO>: implement exceptions to magic
 
 =cut
 
@@ -161,19 +169,19 @@ sub _get_marc21_fields {
        my @m;
        my $last;
        foreach my $row (@{ $marc21 }) {
-               if ($last && (
-                       $last->[0] eq $row->[0] ||              # check if field is same
-                       $last->[1] eq $row->[1] ||              # check for i1
+               if ($last &&
+                       $last->[0] eq $row->[0] &&              # check if field is same
+                       $last->[1] eq $row->[1] &&              # check for i1
                        $last->[2] eq $row->[2]                 # and for i2
-               ) {
-                       $last->[3]->{ $row->[3] } = $row->[4];
-                       warn "## ++ added $row->[0] ^$row->[3]\n";
+               ) {
+                       push @$last, ( $row->[3] , $row->[4] );
+                       warn "## ++ added $row->[0] ^$row->[3] to $last->[0]\n";
                        next;
                } elsif ($last) {
                        push @m, $last;
                }
 
-               push @m, $row;
+               $last = $row;
        }
 
        push @m, $last if ($last);
@@ -251,7 +259,7 @@ sub marc21 {
 
        foreach (@_) {
                my $v = $_;             # make var read-write for Encode
-               next unless (defined($v) && $v !~ /^\s+$/);
+               next unless (defined($v) && $v !~ /^\s*$/);
                from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding);
                push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ];
        }