/[webpac2]/trunk/lib/WebPAC/Input/ISI.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/Input/ISI.pm

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

revision 1302 by dpavlin, Sun Sep 20 19:05:56 2009 UTC revision 1303 by dpavlin, Sun Sep 20 19:56:33 2009 UTC
# Line 104  sub new { Line 104  sub new {
104          my $tag;          my $tag;
105          my $rec;          my $rec;
106    
107          $self->{size} = 0;          my $pos = 0;
108          my $max_size;          my $offset = $self->{offset} || 0;
109          $max_size = ( $self->{offset} || 0 ) + $self->{limit} if $self->{limit};          my $end_pos = 0;
110            $end_pos = $offset + $self->{limit} if $self->{limit};
111    
112          warn "# max_size: $max_size";          warn "# range: $offset - $end_pos";
113    
114          while( $line = <$fh> ) {          while( $line = <$fh> ) {
115                  chomp($line);                  chomp($line);
   
116                  my $v;                  my $v;
117    
118                  if ( $line =~ /^(\S\S)\s(.+)$/ ) {                  if ( $line eq 'EF' ) {
119                                  $tag = $1;                          last;
                                 $v = $2;  
                 } elsif ( $line =~ /^\s{3}(.+)$/ ) {  
                                 $v = $1;  
                                 if ( $tag eq 'CR' && $v =~ m{DOI$} ) {  
                                         my $doi = <$fh>;  
                                         chomp($doi);  
                                         $doi =~ s{^\s{3}}{ } || die "can't find DOI in: $doi";  
                                         $v .= $doi;  
                                 }  
120                  } elsif ( $line eq 'ER' ) {                  } elsif ( $line eq 'ER' ) {
121                            last if $end_pos && $pos >= $end_pos;
122                            $pos++;
123                            next if $offset && $pos < $offset;
124    
125                          # join tags                          # join tags
126                          foreach ( qw/AB DE ID TI SO RP SC FU FX PA JI/ ) {                          foreach ( qw/AB DE ID TI SO RP SC FU FX PA JI/ ) {
127                                  $rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_};                                  $rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_};
# Line 135  sub new { Line 130  sub new {
130                          foreach ( qw/ID SC DE/ ) {                          foreach ( qw/ID SC DE/ ) {
131                                  $rec->{$_} = [ split(/;\s/, $rec->{$_}) ] if defined $rec->{$_};                                  $rec->{$_} = [ split(/;\s/, $rec->{$_}) ] if defined $rec->{$_};
132                          }                          }
133                          $rec->{'000'} = [ ++$self->{size} ];                          $rec->{'000'} = [ $pos ];
134                          push @{ $self->{_rec} }, $rec;                          push @{ $self->{_rec} }, $rec;
135    
                         last if $max_size && $self->{size} == $max_size;  
   
136                          $rec = {};                          $rec = {};
137                          $line = <$fh>;                          $line = <$fh>;
138                          chomp $line;                          chomp $line;
139                          $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );                          $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );
140                  } elsif ( $line eq 'EF' ) {                  } elsif ( $offset && $pos < $offset ) {
141                          last;                          next;
142                    } elsif ( $line =~ /^(\S\S)\s(.+)$/ ) {
143                                    $tag = $1;
144                                    $v = $2;
145                    } elsif ( $line =~ /^\s{3}(.+)$/ ) {
146                                    $v = $1;
147                                    if ( $tag eq 'CR' && $v =~ m{DOI$} ) {
148                                            my $doi = <$fh>;
149                                            chomp($doi);
150                                            $doi =~ s{^\s{3}}{ } || die "can't find DOI in: $doi";
151                                            $v .= $doi;
152                                    }
153    
154                  } elsif ( $line =~ m{^(\S\S)\s*$} ) {                  } elsif ( $line =~ m{^(\S\S)\s*$} ) {
155                          warn "# $arg->{path} +$. empty |$line|\n";                          warn "# $arg->{path} +$. empty |$line|\n";
156                  } else {                  } else {
# Line 161  sub new { Line 166  sub new {
166    
167          }          }
168    
169            $self->{size} = $pos - $offset;
170    
171          $log->debug("loaded ", $self->size, " records");          $log->debug("loaded ", $self->size, " records");
172    
173          $self ? return $self : return undef;          $self ? return $self : return undef;

Legend:
Removed from v.1302  
changed lines
  Added in v.1303

  ViewVC Help
Powered by ViewVC 1.1.26