/[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 899 by dpavlin, Wed Oct 10 19:01:57 2007 UTC revision 1303 by dpavlin, Sun Sep 20 19:56:33 2009 UTC
# Line 6  use strict; Line 6  use strict;
6  use WebPAC::Input;  use WebPAC::Input;
7  use base qw/WebPAC::Common/;  use base qw/WebPAC::Common/;
8    
9    use Data::Dump qw/dump/;
10    
11  =head1 NAME  =head1 NAME
12    
13  WebPAC::Input::ISI - support for ISI Export Format  WebPAC::Input::ISI - support for ISI Export Format
14    
 =head1 VERSION  
   
 Version 0.00  
   
15  =cut  =cut
16    
17  our $VERSION = '0.00';  our $VERSION = '0.03';
   
18    
19  =head1 SYNOPSIS  =head1 SYNOPSIS
20    
# Line 54  path to ISI export file Line 51  path to ISI export file
51    
52  =cut  =cut
53    
54    my $subfields = {
55            'CR' => sub {
56                    my $full_cr = shift;
57                    my @v = split(/, /, $full_cr);
58                    my $f = { full => $full_cr };
59                    foreach ( qw/author year reference volume page doi/ ) {
60                            if ( my $tmp = shift @v ) {
61                                    $f->{$_} = $tmp;
62                            }
63                    }
64                    if ( $f->{author} =~ /^\*(.+)/ ) {
65                            delete $f->{author};
66                            $f->{institution} = $1;
67                    }
68                    $f->{doi} =~ s{DOI\s+}{} if $f->{doi}; # strip DOI prefix
69                    return $f;
70            },
71    };
72    
73  sub new {  sub new {
74          my $class = shift;          my $class = shift;
75          my $self = {@_};          my $self = {@_};
# Line 88  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
126                            foreach ( qw/AB DE ID TI SO RP SC FU FX PA JI/ ) {
127                                    $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                  push @{ $rec->{$tag} }, $v;                  if ( defined $v ) {
161                            $v = $subfields->{$tag}->($v) if defined $subfields->{$tag};
162    
163                            $log->debug("$tag: ", sub { dump( $v ) });
164                            push @{ $rec->{$tag} }, $v;
165                    }
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 146  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
207    
208    L<http://isibasic.com/help/helpprn.html> is only sane source of document format which Google could find...
209    
210  =head1 AUTHOR  =head1 AUTHOR
211    
212  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

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

  ViewVC Help
Powered by ViewVC 1.1.26