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

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

revision 904 by dpavlin, Fri Oct 12 12:07:35 2007 UTC revision 1303 by dpavlin, Sun Sep 20 19:56:33 2009 UTC
# Line 12  use Data::Dump qw/dump/; Line 12  use Data::Dump qw/dump/;
12    
13  WebPAC::Input::ISI - support for ISI Export Format  WebPAC::Input::ISI - support for ISI Export Format
14    
 =head1 VERSION  
   
 Version 0.02  
   
15  =cut  =cut
16    
17  our $VERSION = '0.02';  our $VERSION = '0.03';
18    
19  =head1 SYNOPSIS  =head1 SYNOPSIS
20    
# Line 57  path to ISI export file Line 53  path to ISI export file
53    
54  my $subfields = {  my $subfields = {
55          'CR' => sub {          'CR' => sub {
56                  my @v = split(/, /, shift);                  my $full_cr = shift;
57                  my $f;                  my @v = split(/, /, $full_cr);
58                  foreach ( qw/author year reference volume page/ ) {                  my $f = { full => $full_cr };
59                    foreach ( qw/author year reference volume page doi/ ) {
60                          if ( my $tmp = shift @v ) {                          if ( my $tmp = shift @v ) {
61                                  $f->{$_} = $tmp;                                  $f->{$_} = $tmp;
62                          }                          }
# Line 68  my $subfields = { Line 65  my $subfields = {
65                          delete $f->{author};                          delete $f->{author};
66                          $f->{institution} = $1;                          $f->{institution} = $1;
67                  }                  }
68                    $f->{doi} =~ s{DOI\s+}{} if $f->{doi}; # strip DOI prefix
69                  return $f;                  return $f;
70          },          },
71  };  };
# Line 106  sub new { Line 104  sub new {
104          my $tag;          my $tag;
105          my $rec;          my $rec;
106    
107            my $pos = 0;
108            my $offset = $self->{offset} || 0;
109            my $end_pos = 0;
110            $end_pos = $offset + $self->{limit} if $self->{limit};
111    
112            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;  
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/ ) {                          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->{$_};
128                          }                          }
129                            # split on ;
130                            foreach ( qw/ID SC DE/ ) {
131                                    $rec->{$_} = [ split(/;\s/, $rec->{$_}) ] if defined $rec->{$_};
132                            }
133                            $rec->{'000'} = [ $pos ];
134                          push @{ $self->{_rec} }, $rec;                          push @{ $self->{_rec} }, $rec;
135    
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*$} ) {
155                            warn "# $arg->{path} +$. empty |$line|\n";
156                  } else {                  } else {
157                          $log->logdie("can't parse +$. $arg->{path} : $line");                          $log->logdie("can't parse +$. $arg->{path} |$line|");
158                  }                  }
159    
160                  if ( defined $v ) {                  if ( defined $v ) {
# Line 141  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;
# Line 173  Return number of records in database Line 200  Return number of records in database
200    
201  sub size {  sub size {
202          my $self = shift;          my $self = shift;
203          return $#{$self->{_rec}} + 1;          return $self->{size};
204  }  }
205    
206  =head1 SEE ALSO  =head1 SEE ALSO

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

  ViewVC Help
Powered by ViewVC 1.1.26