/[webpac2]/trunk/lib/WebPAC/Normalize.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Normalize.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 541 by dpavlin, Thu Jun 29 21:18:50 2006 UTC revision 543 by dpavlin, Thu Jun 29 21:19:08 2006 UTC
# Line 152  Get all fields defined by calls to C<mar Line 152  Get all fields defined by calls to C<mar
152    
153          $marc->add_fields( WebPAC::Normalize:_get_marc21_fields() );          $marc->add_fields( WebPAC::Normalize:_get_marc21_fields() );
154    
155    
156    
157    We are using I<magic> which detect repeatable fields only from
158    sequence of field/subfield data generated by normalization.
159    
160    Repeatable field is created if there is second occurence of same subfield or
161    if any of indicators are different. This is sane for most cases except for
162    non-repeatable fields with repeatable subfields.
163    
164    B<TODO>: implement exceptions to magic
165    
166  =cut  =cut
167    
168  sub _get_marc21_fields {  sub _get_marc21_fields {
169          return @{$marc21};          my @m;
170            my $last;
171            foreach my $row (@{ $marc21 }) {
172                    if ($last &&
173                            $last->[0] eq $row->[0] &&              # check if field is same
174                            $last->[1] eq $row->[1] &&              # check for i1
175                            $last->[2] eq $row->[2]                 # and for i2
176                    ) {
177                            push @$last, ( $row->[3] , $row->[4] );
178                            warn "## ++ added $row->[0] ^$row->[3] to $last->[0]\n";
179                            next;
180                    } elsif ($last) {
181                            push @m, $last;
182                    }
183    
184                    $last = $row;
185            }
186    
187            push @m, $last if ($last);
188    
189            return @m;
190  }  }
191    
192  =head1 Functions to create C<data_structure>  =head1 Functions to create C<data_structure>
# Line 228  sub marc21 { Line 259  sub marc21 {
259    
260          foreach (@_) {          foreach (@_) {
261                  my $v = $_;             # make var read-write for Encode                  my $v = $_;             # make var read-write for Encode
262                  next unless (defined($v) && $v !~ /^\s+$/);                  next unless (defined($v) && $v !~ /^\s*$/);
263                  from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding);                  from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding);
264                  push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ];                  push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ];
265          }          }

Legend:
Removed from v.541  
changed lines
  Added in v.543

  ViewVC Help
Powered by ViewVC 1.1.26