From df7e60bd03f18a58a67c8d46f15d91fa98a7e5de Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Fri, 24 Apr 2009 14:52:52 +0000 Subject: [PATCH] first tests passing, first records parsed --- .../lib/Equinox/Migration/MapDrivenMARCXMLProc.pm | 20 +++++++++------ Equinox-Migration/t/03-MapDrivenMARCXMLProc.t | 26 +++++++++++++++++++- Equinox-Migration/t/corpus/mdmp-0.txt | 4 +- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm index bf9144d..2c789c9 100644 --- a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm +++ b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm @@ -106,7 +106,7 @@ sub parse_record { # get the next record and wipe current parsed record return 0 unless defined $self->{data}{recs}[ $self->{data}{rptr} ]; my $record = $self->{data}{recs}[ $self->{data}{rptr} ]; - $self->{data}{crec} = { bib => undef, multi => undef }; + $self->{data}{crec} = { egid => undef, bib => undef, tags => undef }; my @fields = $record->children; for my $f (@fields) @@ -116,7 +116,7 @@ sub parse_record { $record->purge; $self->{data}{rptr}++; - return $self->format_record; + return $self->{data}{crec}; } =head2 process_field @@ -127,18 +127,19 @@ sub process_field { my ($self, $field) = @_; my $map = $self->{map}; my $tag = $field->{'att'}->{'tag'}; - my $parsed = $self->{data}{crec}; + my $crec = $self->{data}{crec}; # datafields if (defined $tag) { if ($tag == 903) { my $sub = $field->first_child('subfield'); - $parsed->{egid} = $sub->text;; + $crec->{egid} = $sub->text;; } elsif ($map->has($tag)) { - push @{$parsed->{tags}}, { tag => $tag }; + push @{$crec->{tags}}, { tag => $tag, uni => undef, multi => undef }; my @subs = $field->children('subfield'); for my $sub (@subs) { $self->process_subs($tag, $sub) } + # check map to ensure all declared subs are in } } } @@ -158,23 +159,26 @@ sub process_subs { my $s = $self->{data}{stag}; return unless (defined $s->{$tag}); + # set a value, total-seen count and records-seen-in count $u->{$tag}{$code}{value} = $sub->text unless defined $u->{$tag}{$code}; $u->{$tag}{$code}{count}++; + $u->{$tag}{$code}{rcnt}++ unless ($u->{$tag}{$code}{last} == $self->{data}{rptr}); + $u->{$tag}{$code}{last} = $self->{data}{rptr}; return; } - my $data = $self->{data}{crec}{tags}[-1]; + my $dataf = $self->{data}{crec}{tags}[-1]; my $field = $map->field($tag, $code); # handle modifiers if (defined $map->mods($field)) { if ($map->mods($field) eq 'multi') { my $name = $tag . $code; - push @{$data->{multi}{$name}}, $sub->text; + push @{$dataf->{multi}{$name}}, $sub->text; } } - $data->{uni}{$code} = $sub->text; + $dataf->{uni}{$code} = $sub->text; } =head1 PARSED RECORDS diff --git a/Equinox-Migration/t/03-MapDrivenMARCXMLProc.t b/Equinox-Migration/t/03-MapDrivenMARCXMLProc.t index c3e3ba0..5e1f21d 100644 --- a/Equinox-Migration/t/03-MapDrivenMARCXMLProc.t +++ b/Equinox-Migration/t/03-MapDrivenMARCXMLProc.t @@ -22,7 +22,31 @@ my $mp = Equinox::Migration::MapDrivenMARCXMLProc->new( marcfile => 't/corpus/md mapfile => 't/corpus/mdmpmap-00.txt', ); is(ref $mp, "Equinox::Migration::MapDrivenMARCXMLProc", "self is self"); - # parsing +# +# with map-00, only the 999$a should be captured +# 903$a will *always* be captured, of course my $rec = $mp->parse_record; is (defined $rec, 1); +is ($rec->{egid}, 9000000, '903 captured'); +is ($rec->{tags}[0]{tag}, 999, 'first (only) tag should be 999'); +is ($rec->{tags}[0]{uni}{a}, "MYS DEM", 'single-ocurrance subfield "a" should be "MYS DEM"'); +is ($rec->{tags}[0]{uni}{b}, undef, 'only one uni subfield defined'); +is ($rec->{tags}[0]{multi}, undef, 'no multi subfields were defined'); +is ($rec->{tags}[1], undef, 'Only one tag in map'); +is ($rec->{bib}, undef, 'No bib-level fields in map'); +# let's go ahead and look at the rest of the file +$rec = $mp->parse_record; +is ($rec->{egid}, 9000001, '903 #2'); +is ($rec->{tags}[0]{tag}, 999, 'tag id 2'); +is ($rec->{tags}[0]{uni}{a}, "MYS 2", 'subfield value 2'); +$rec = $mp->parse_record; +is ($rec->{egid}, 9000002, '903 #3'); +is ($rec->{tags}[0]{tag}, 999, 'tag id 3'); +is ($rec->{tags}[0]{uni}{a}, "FOO BAR", 'subfield value 3'); +$rec = $mp->parse_record; +is ($rec->{egid}, 9000003, '903 #4'); +is ($rec->{tags}[0]{tag}, 999, 'tag id 4'); +is ($rec->{tags}[0]{uni}{a}, "FIC DEV", 'subfield value 4'); +$rec = $mp->parse_record; +is ($rec, 0, 'no more records'); diff --git a/Equinox-Migration/t/corpus/mdmp-0.txt b/Equinox-Migration/t/corpus/mdmp-0.txt index 3fbed49..ea4431d 100644 --- a/Equinox-Migration/t/corpus/mdmp-0.txt +++ b/Equinox-Migration/t/corpus/mdmp-0.txt @@ -1,6 +1,6 @@ 00708nam a2200229u 4500 ocm03650663 OCoLC 19840321193705.0 971231s1978 nyu 00011 eng 77091474 0151152780 DLC DLC IIA PZ4.D3792 By PS3554.E472 813/.5/4 Fic DeM DeMille, Nelson. By the rivers of Babylon : a novel / by Nelson De Mille. 1st ed. New York : Harcourt Brace Jovanovich, c1978. 391 p. ; 24 cm. a3 MYS DEM DEWEY 1 010003 7/9/2008 6/30/2008 MYSTERY CARNEGIE 8 $25.00 Y Y BOOK 11/22/2002 MYSTERY ADULT 9000000 - 00770nam a2200265u 4500 ocm07175079 OCoLC 19810601170611.0 971231s1981 nyu 00011 eng 80029126 044001140X DLC DLC IIA PS3554.E472 C3 813/.54 19 Fic DeM DeMille, Nelson. Cathedral : a novel / by Nelson DeMille. New York : Delacorte Press, c1981. 8105 483 p. "A Bernard Geis Associates book." MYS 10004 MYS DeM 80 a4 MYS DEM DEWEY 1 010004 11/17/2007 10/27/2007 MYSTERY CARNEGIE 10 $25.00 Y Y BOOK 11/22/2002 MYSTERY ADULT 9000001 - 00725nam a2200241u 4500 ocm17300504 OCoLC 19910515200843.0 971231s1988 nyu 00011 eng 87034637 0446513059 : $17.95 DLC DLC IIA PS3554.E472 C48 1988 813/.54 19 Fic DeM DeMille, Nelson. The charm school / Nelson DeMille. New York, NY : Warner Books, 1988. 533 p. ; 24 cm. MYS 10012 17.95 MYS DeM 80 a8 MYS DEM DEWEY 1 010012 11/20/2007 11/15/2007 MYSTERY CARNEGIE 10 $17.95 Y Y BOOK 11/22/2002 MYSTERY ADULT 9000002 + 00770nam a2200265u 4500 ocm07175079 OCoLC 19810601170611.0 971231s1981 nyu 00011 eng 80029126 044001140X DLC DLC IIA PS3554.E472 C3 813/.54 19 Fic DeM DeMille, Nelson. Cathedral : a novel / by Nelson DeMille. New York : Delacorte Press, c1981. 8105 483 p. "A Bernard Geis Associates book." MYS 10004 MYS DeM 80 a4 MYS 2 DEWEY 1 010004 11/17/2007 10/27/2007 MYSTERY CARNEGIE 10 $25.00 Y Y BOOK 11/22/2002 MYSTERY ADULT 9000001 + 00725nam a2200241u 4500 ocm17300504 OCoLC 19910515200843.0 971231s1988 nyu 00011 eng 87034637 0446513059 : $17.95 DLC DLC IIA PS3554.E472 C48 1988 813/.54 19 Fic DeM DeMille, Nelson. The charm school / Nelson DeMille. New York, NY : Warner Books, 1988. 533 p. ; 24 cm. MYS 10012 17.95 MYS DeM 80 a8 FOO BAR DEWEY 1 010012 11/20/2007 11/15/2007 MYSTERY CARNEGIE 10 $17.95 Y Y BOOK 11/22/2002 MYSTERY ADULT 9000002 00792nam a2200277u 4500 ocm21442030 OCoLC 19900806213946.0 971231s1990 nyu 00011 eng 90036314 0671689754 : $18.95 DLC DLC IIA PS3554.E9273 M6 1990 813/.54 20 Fic Dev Deveraux, Jude. Mountain laurel / Jude Deveraux. New York : Pocket Books, c1990. 9007 312 p. FIC Fic Dev 10015 18.95 STORAGE Fic Dev 14355 18.95 2 71 a9 FIC DEV DEWEY 1 010015 3/9/2009 2/16/2009 FICTION CARNEGIE 14 $18.95 Y Y BOOK 11/22/2002 FICTION ADULT 9000003 -- 1.7.2.5