-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package PICA::Parser::Import; | ||
use v5.14.1; | ||
use utf8; | ||
|
||
our $VERSION = '2.09'; | ||
|
||
use charnames ':full'; | ||
use Carp qw(carp croak); | ||
|
||
use parent 'PICA::Parser::Base'; | ||
|
||
sub _next_record { | ||
my ($self) = @_; | ||
|
||
my $reader = $self->{reader}; | ||
my $line; | ||
|
||
# All data before the first record separator is ignored | ||
if (!$self->count) { | ||
do { | ||
$line = readline($reader); | ||
return unless defined $line; | ||
} while ($line =~ /^\x1D$/); | ||
} | ||
|
||
my @record; | ||
while (1) { | ||
$line = readline($reader); | ||
if (!defined $line) { | ||
@record ? last : return; | ||
} | ||
|
||
next if $line =~ /^#|^\s*$/; # ignore empty or comment lines | ||
last if $line =~ /^\x1D$/; | ||
chomp $line; | ||
|
||
if ($line | ||
=~ m/^\x1E([012][0-9][0-9][A-Z@])(\/(\d{2,3}))?\s((\x1F[^\x1F]+)+)$/ | ||
) | ||
{ | ||
my $tag = $1; | ||
my $occ = $3 > 0 ? $3 : ''; | ||
my @sf = split /\x1F/, $4; | ||
shift @sf; | ||
push @record, [$tag, $occ, map {split //, $_, 2} @sf]; | ||
} | ||
elsif ($self->{strict}) { | ||
croak "ERROR: invalid PICA field structure \"$line\""; | ||
} | ||
else { | ||
carp | ||
"WARNING: invalid PICA field structure \"$line\". Skipped field"; | ||
next; | ||
} | ||
|
||
} | ||
|
||
return \@record; | ||
} | ||
|
||
1; | ||
__END__ | ||
=encoding UTF-8 | ||
=head1 NAME | ||
PICA::Parser::Import - PICA Import format parser | ||
=head1 DESCRIPTION | ||
Parses PICA+ records in PICA Import format (also known as "normalized title | ||
format", see L<https://format.gbv.de/pica/import>). | ||
Fields or subfields spread over several lines are not supported! | ||
See L<PICA::Parser::Base> for synopsis and configuration. | ||
The counterpart of this module is L<PICA::Writer::Import>. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
All data before the first record separator (ASCII 29) is ignored. | ||
|
||
# comment | ||
|
||
002@ 0Aan | ||
003@ 012345 | ||
010@ achi | ||
011@ a2004n2004.01 | ||
012X 00xy | ||
019@ aXB-CN | ||
021A a我国民事立法的回顾与展望fHistory and perspective of China civil lawh柳经纬主编; | ||
101@ a120cPICAdOldenburg, IBIT Universität Oldenburg <715> | ||
101B 015-01-09t15:32:38.000 | ||
101D 015-01-09b9330a0715 | ||
101U 0utf8 | ||
145Z/40 a$btest$c... | ||
201B/01 015-01-09t15:32:38.000 | ||
201D/01 015-01-09b9330a0715 | ||
201U/01 0utf8 | ||
203@/01 0917400194xy | ||
208@/01 a15-01-09bz | ||
209A/01 f108a401-06356/09dgx00 | ||
## Another comment | ||
003@ 067890 |