/[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 898 by dpavlin, Wed Oct 10 19:01:55 2007 UTC revision 902 by dpavlin, Wed Oct 10 21:00:27 2007 UTC
# Line 12  WebPAC::Input::ISI - support for ISI Exp Line 12  WebPAC::Input::ISI - support for ISI Exp
12    
13  =head1 VERSION  =head1 VERSION
14    
15  Version 0.00  Version 0.01
16    
17  =cut  =cut
18    
19  our $VERSION = '0.00';  our $VERSION = '0.01';
20    
21    
22  =head1 SYNOPSIS  =head1 SYNOPSIS
# Line 54  path to ISI export file Line 54  path to ISI export file
54    
55  =cut  =cut
56    
57    my $subfields = {
58            'CR' => sub {
59                    my @v = split(/, /, shift);
60                    my $f;
61                    foreach ( qw/author year reference volume page/ ) {
62                            if ( my $tmp = shift @v ) {
63                                    $f->{$_} = $tmp;
64                            }
65                    }
66                    if ( $f->{author} =~ /^\*(.+)/ ) {
67                            delete $f->{author};
68                            $f->{institution} = $1;
69                    }
70                    return $f;
71            },
72    };
73    
74  sub new {  sub new {
75          my $class = shift;          my $class = shift;
76          my $self = {@_};          my $self = {@_};
# Line 85  sub new { Line 102  sub new {
102    
103          $log->info("opening $format $version database '$arg->{path}'");          $log->info("opening $format $version database '$arg->{path}'");
104    
105            my $tag;
106            my $rec;
107    
108            while( $line = <$fh> ) {
109                    chomp($line);
110    
111                    my $v;
112    
113                    if ( $line =~ /^(\S\S)\s(.+)$/ ) {
114                                    $tag = $1;
115                                    $v = $2;
116                    } elsif ( $line =~ /^\s{3}(.+)$/ ) {
117                                    $v = $1;
118                    } elsif ( $line eq 'ER' ) {
119                            # join tags
120                            foreach ( qw/AB DE ID TI/ ) {
121                                    $rec->{$_} = join(' ', @{ $rec->{$_} }) if defined $rec->{$_};
122                            }
123                            push @{ $self->{_rec} }, $rec;
124                            $rec = {};
125                            $line = <$fh>;
126                            chomp $line;
127                            $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );
128                    } elsif ( $line eq 'EF' ) {
129                            last;
130                    } else {
131                            $log->logdie("can't parse +$. $arg->{path} : $line");
132                    }
133    
134                    $v = $subfields->{$tag}->($v) if defined $subfields->{$tag};
135    
136                    push @{ $rec->{$tag} }, $v;
137    
138            }
139    
140            $log->debug("loaded ", $self->size, " records");
141    
142          $self ? return $self : return undef;          $self ? return $self : return undef;
143  }  }
144    
# Line 92  sub new { Line 146  sub new {
146    
147  Return record with ID C<$mfn> from database  Return record with ID C<$mfn> from database
148    
149    my $rec = $input->fetch_rec( $mfn, $filter_coderef);    my $rec = $input->fetch_rec( $mfn, $filter_coderef );
150    
151  =cut  =cut
152    
153  sub fetch_rec {  sub fetch_rec {
154          my $self = shift;          my $self = shift;
155    
156          my ($mfn, $filter_coderef) = @_;          my ( $mfn, $filter_coderef ) = @_;
157    
158          my $rec;          return $self->{_rec}->[$mfn-1];
   
         return $rec;  
159  }  }
160    
161    
# Line 117  Return number of records in database Line 169  Return number of records in database
169    
170  sub size {  sub size {
171          my $self = shift;          my $self = shift;
172          return 2;          return $#{$self->{_rec}} + 1;
173  }  }
174    
175    =head1 SEE ALSO
176    
177    L<http://isibasic.com/help/helpprn.html> is only sane source of document format which Google could find...
178    
179  =head1 AUTHOR  =head1 AUTHOR
180    
181  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.898  
changed lines
  Added in v.902

  ViewVC Help
Powered by ViewVC 1.1.26