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

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

revision 1295 by dpavlin, Tue Apr 21 21:06:29 2009 UTC revision 1296 by dpavlin, Sat Sep 19 23:29:23 2009 UTC
# Line 11  use Data::Dump qw/dump/; Line 11  use Data::Dump qw/dump/;
11    
12  =head1 NAME  =head1 NAME
13    
14  WebPAC::Input::Ovid - support for Ovid citation export  WebPAC::Input::Ovid - support for Ovid citation export (BRS/Tagged and Direct Export)
15    
16  =head1 VERSION  =head1 VERSION
17    
# Line 30  Open file in Ovid citation export fromat Line 30  Open file in Ovid citation export fromat
30          path => '/path/to/ovid-cites.txt',          path => '/path/to/ovid-cites.txt',
31   );   );
32    
33    You can also specify file glob:
34    
35      my $input = WebPAC::Input::Ovid->new( path => '/path/to/ovid.*.txt' );
36    
37  =head1 FUNCTIONS  =head1 FUNCTIONS
38    
39  =head2 new  =head2 new
# Line 66  sub new { Line 70  sub new {
70    
71          my $log = $self->_get_logger();          my $log = $self->_get_logger();
72    
73          open( my $fh, '<', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");          my @paths;
74    
75          $log->info("reading '$arg->{path}'");          if ( $arg->{path} =~ m/\*/ ) {
76                    @paths = glob $arg->{path};
77            } else {
78                    @paths = ( $arg->{path} );
79            }
80    
         my $rec;  
81          my $size = 0;          my $size = 0;
         my $tag;  
   
82          $self->{_rec} = [];          $self->{_rec} = [];
83    
84          while( my $line = <$fh> ) {          my $max_size;
85                  $line =~ s{[\r\n]+$}{};          $max_size = ( $self->{offset} || 0 ) + $self->{limit} if $self->{limit};
86                  next if $line eq '';  
87            foreach my $path ( @paths ) {
88                  warn "<< $line\n" if $debug;  
89                    open( my $fh, '<', $path ) || $log->logconfess("can't open $path: $!");
90                  if ( $line =~ m/^<(\d+)>$/ ) {                  $log->info("reading '$path'");
91                          push @{ $self->{_rec} }, $rec if $rec;  
92                          warn "## rec = ",dump( $rec ),$/ if $debug;                  my $tag;
93                          my $expect_rec = $#{ $self->{_rec} } + 2;                  my $rec;
94                          warn "wrong Ovid record number: $1 != $expect_rec" if $debug && $1 != $expect_rec;  
95                          $rec = { '000' => [ $1 ] };                  while( my $line = <$fh> ) {
96                  } elsif ( $line =~ /^(\w.+)/ ) {                          $line =~ s{[\r\n]+$}{};
97                          $tag = $1;                          next if $line eq '';
98                          warn "++ $tag\n" if $debug;  
99                  } elsif ( $line =~ /^\s\s(.+)/ ) {                          warn "<< $line\n" if $debug;
100                          my $v = $1;  
101                          $v =~ s{[\s\.]+$}{};                          if ( $line =~ m/^<(\d+)>$/ ) {
102                          $rec->{$tag} = [ $v ];                                  last if $max_size && $size > $max_size;
103                  } else {  
104                          warn "### skip: '$line'\n" if $debug;                                  push @{ $self->{_rec} }, $rec if $rec;
105                                    warn "## rec = ",dump( $rec ),$/ if $debug;
106                                    my $expect_rec = $#{ $self->{_rec} } + 2;
107                                    warn "wrong Ovid record number: $1 != $expect_rec" if $debug && $1 != $expect_rec;
108                                    $rec = { '000' => [ ++$size ] };
109                            } elsif ( $line =~ /^(\w+)\s+(-\s)?(.*)/ ) {
110                                    $tag = $1;
111                                    warn "++ $tag\n" if $debug;
112                                    $rec->{$tag} = [ $3 ] if $3;
113                            } elsif ( $line =~ /^\s+(-\s)?(.+)/ ) {
114                                    push @{ $rec->{$tag} }, $2;
115                            } else {
116                                    warn "### skip: '$line'\n" if $debug;
117                            }
118    
119                  }                  }
120    
121          }                  # save last rec
122                    push @{ $self->{_rec} }, $rec if $rec;
123                    warn "### rec ",dump $rec if $debug;
124    
125          # save last rec                  $log->debug("loaded ", $self->size, " records from $path");
         push @{ $self->{_rec} }, $rec if $rec;  
126    
127          $log->debug("loaded ", $self->size, " records");          }
128    
129          $self ? return $self : return undef;          $self ? return $self : return undef;
130  }  }

Legend:
Removed from v.1295  
changed lines
  Added in v.1296

  ViewVC Help
Powered by ViewVC 1.1.26