/[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 544 by dpavlin, Thu Jun 29 21:52:51 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                            $last->[3] ne $row->[3]                 # and subfield is different
177                    ) {
178                            push @$last, ( $row->[3] , $row->[4] );
179                            warn "## ++ added $row->[0] ^$row->[3] to $last->[0]\n";
180                            next;
181                    } elsif ($last) {
182                            push @m, $last;
183                    }
184    
185                    $last = $row;
186            }
187    
188            push @m, $last if ($last);
189    
190            return @m;
191  }  }
192    
193  =head1 Functions to create C<data_structure>  =head1 Functions to create C<data_structure>
# Line 228  sub marc21 { Line 260  sub marc21 {
260    
261          foreach (@_) {          foreach (@_) {
262                  my $v = $_;             # make var read-write for Encode                  my $v = $_;             # make var read-write for Encode
263                  next unless (defined($v) && $v !~ /^\s+$/);                  next unless (defined($v) && $v !~ /^\s*$/);
264                  from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding);                  from_to($v, 'iso-8859-2', $marc_encoding) if ($marc_encoding);
265                  push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ];                  push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ];
266          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26