/[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

trunk/lib/WebPAC/Input/ISI.pm revision 904 by dpavlin, Fri Oct 12 12:07:35 2007 UTC branches/Sack/lib/WebPAC/Input/ISI.pm revision 1310 by dpavlin, Mon Sep 21 19:04:14 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 $offset = $self->{offset} || 0;
108            my $limit  = $self->{limit}  || 0;
109    
110            my $file_pos = 0;
111            my $end_pos  = 0;
112            $end_pos = $offset + $limit if $limit;
113    
114            $self->{_rec} = [];
115            
116            warn "# offset: $offset limit: $limit end: $end_pos";
117    
118          while( $line = <$fh> ) {          while( $line = <$fh> ) {
119                  chomp($line);                  chomp($line);
   
120                  my $v;                  my $v;
121    
122                  if ( $line =~ /^(\S\S)\s(.+)$/ ) {                  if ( $line eq 'EF' ) {
123                                  $tag = $1;                          last;
                                 $v = $2;  
                 } elsif ( $line =~ /^\s{3}(.+)$/ ) {  
                                 $v = $1;  
124                  } elsif ( $line eq 'ER' ) {                  } elsif ( $line eq 'ER' ) {
125                          # join tags                          $file_pos++;
126                          foreach ( qw/AB DE ID TI/ ) {                          last if $end_pos && $file_pos > $end_pos;
127                                  $rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_};  
128                            if ( ! $offset || $file_pos > $offset ) {
129    
130                                    # join tags
131                                    foreach ( qw/AB DE ID TI SO RP SC FU FX PA JI/ ) {
132                                            $rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_};
133                                    }
134                                    # split on ;
135                                    foreach ( qw/ID SC DE/ ) {
136                                            $rec->{$_} = [ split(/;\s/, $rec->{$_}) ] if defined $rec->{$_};
137                                    }
138                                    $rec->{'000'} = [ $file_pos ];
139                                    push @{ $self->{_rec} }, $rec;
140                          }                          }
141                          push @{ $self->{_rec} }, $rec;  
142                          $rec = {};                          $rec = {};
143                          $line = <$fh>;                          $line = <$fh>;
144                          chomp $line;                          chomp $line;
145                          $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );                          $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );
146                  } elsif ( $line eq 'EF' ) {                  } elsif ( $offset && $file_pos < $offset ) {
147                          last;                          next;
148                    } elsif ( $line =~ /^(\S\S)\s(.+)$/ ) {
149                            $tag = $1;
150                            $v = $2;
151                    } elsif ( $line =~ /^\s{3}(.+)$/ ) {
152                            $v = $1;
153                            if ( $tag eq 'CR' && $v =~ m{DOI$} ) {
154                                    my $doi = <$fh>;
155                                    chomp($doi);
156                                    $doi =~ s{^\s{3}}{ } || die "can't find DOI in: $doi";
157                                    $v .= $doi;
158                            }
159                    } elsif ( $line =~ m{^(\S\S)\s*$} ) {
160                            warn "# $arg->{path} +$. empty |$line|\n";
161                  } else {                  } else {
162                          $log->logdie("can't parse +$. $arg->{path} : $line");                          $log->logdie("can't parse +$. $arg->{path} |$line|");
163                  }                  }
164    
165                  if ( defined $v ) {                  if ( defined $v ) {
# Line 140  sub new { Line 170  sub new {
170                  }                  }
171    
172          }          }
   
173          $log->debug("loaded ", $self->size, " records");          $log->debug("loaded ", $self->size, " records");
174    
175          $self ? return $self : return undef;          $self ? return $self : return undef;
# Line 159  sub fetch_rec { Line 188  sub fetch_rec {
188    
189          my ( $mfn, $filter_coderef ) = @_;          my ( $mfn, $filter_coderef ) = @_;
190    
191            $mfn -= $self->{offset} if $self->{offset};
192          return $self->{_rec}->[$mfn-1];          return $self->{_rec}->[$mfn-1];
193  }  }
194    
# Line 173  Return number of records in database Line 203  Return number of records in database
203    
204  sub size {  sub size {
205          my $self = shift;          my $self = shift;
206          return $#{$self->{_rec}} + 1;          $#{ $self->{_rec} } + 1;
207  }  }
208    
209  =head1 SEE ALSO  =head1 SEE ALSO

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

  ViewVC Help
Powered by ViewVC 1.1.26