From: Tara L Andrews Date: Mon, 16 Jan 2012 22:09:37 +0000 (+0100) Subject: fix niggly bug in TEI parsing; test GraphML in/out X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=56eefa047aca3def7449cb79ac461b468b51e54c;p=scpubgit%2Fstemmatology.git fix niggly bug in TEI parsing; test GraphML in/out --- diff --git a/TODO b/TODO index b02cc5f..950e7ea 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ * support and test deletion of a tradition * support and test deletion of a relationship -* support and test graphml output for relationships diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 00b48b7..74b9f47 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -475,6 +475,43 @@ transposition information and position information. Unless $recalculate is passed (and is a true value), the method will return a cached copy of the SVG after the first call to the method. +=begin testing + +use Text::Tradition; + +my $READINGS = 311; +my $PATHS = 361; + +my $datafile = 't/data/florilegium_tei_ps.xml'; +my $tradition = Text::Tradition->new( 'input' => 'TEI', + 'name' => 'test0', + 'file' => $datafile, + 'linear' => 1 ); + +ok( $tradition, "Got a tradition object" ); +is( scalar $tradition->witnesses, 13, "Found all witnesses" ); +ok( $tradition->collation, "Tradition has a collation" ); + +my $c = $tradition->collation; +is( scalar $c->readings, $READINGS, "Collation has all readings" ); +is( scalar $c->paths, $PATHS, "Collation has all paths" ); +is( scalar $c->relationships, 0, "Collation has all relationships" ); + +# Add a few relationships +$c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } ); +$c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } ); +$c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } ); + +# Now write it to GraphML and parse it again. + +my $graphml = $c->as_graphml; +my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml ); +is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" ); +is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" ); +is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" ); + +=end testing + =cut sub as_graphml { @@ -1039,7 +1076,7 @@ sub flatten_ranks { my $key = $rdg->rank . "||" . $rdg->text; if( exists $unique_rank_rdg{$key} ) { # Combine! - # print STDERR "Combining readings at same rank: $key\n"; + # print STDERR "Combining readings at same rank: $key\n"; $self->merge_readings( $unique_rank_rdg{$key}, $rdg ); } else { $unique_rank_rdg{$key} = $rdg; diff --git a/lib/Text/Tradition/Collation/Reading.pm b/lib/Text/Tradition/Collation/Reading.pm index 7c0daa9..0b57ff8 100644 --- a/lib/Text/Tradition/Collation/Reading.pm +++ b/lib/Text/Tradition/Collation/Reading.pm @@ -143,7 +143,7 @@ around BUILDARGS => sub { # ID to match. if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) { - $args->{'text'} = sprintf( "#LACUNA_%s#", $args->{'id'} ); + $args->{'text'} = '#LACUNA#'; } elsif( exists $args->{'is_start'} ) { $args->{'id'} = '#START#'; # Change the ID to ensure we have only one $args->{'text'} = '#START#'; diff --git a/lib/Text/Tradition/Parser/TEI.pm b/lib/Text/Tradition/Parser/TEI.pm index 65de99e..afea435 100644 --- a/lib/Text/Tradition/Parser/TEI.pm +++ b/lib/Text/Tradition/Parser/TEI.pm @@ -62,8 +62,8 @@ my $t = Text::Tradition->new( is( ref( $t ), 'Text::Tradition', "Parsed parallel-segmentation TEI" ); if( $t ) { - is( scalar $t->collation->readings, 319, "Collation has all readings" ); - is( scalar $t->collation->paths, 375, "Collation has all paths" ); + is( scalar $t->collation->readings, 311, "Collation has all readings" ); + is( scalar $t->collation->paths, 361, "Collation has all paths" ); } =end testing @@ -171,15 +171,12 @@ sub parse { my $source = shift @uncorrected; # the start node warn "Something weird!" unless $source eq $c->start; foreach my $rdg ( @uncorrected ) { - my $source_base = grep { $_ eq $sig } $c->reading_witnesses( $source ); - my $target_base = grep { $_ eq $sig } $c->reading_witnesses( $rdg ); - unless( $source_base && $target_base ) { - # print STDERR sprintf( "Adding path %s from %s -> %s\n", - # $sig.$c->ac_label, $source->id, $rdg->id ); - $c->add_path( $source, $rdg, $sig.$c->ac_label ); - } - $source = $rdg; + unless( $c->has_path( $source, $rdg, $sig ) ) { + $c->add_path( $source, $rdg, $sig.$c->ac_label ); + } + $source = $rdg; } + warn "Something else weird!" unless $source eq $c->end; # print STDERR "Adding a.c. version for witness $sig\n"; $tradition->witness( $sig )->is_layered( 1 ); } diff --git a/t/01app.t b/t/01app.t index 0c9cfda..98728ec 100644 --- a/t/01app.t +++ b/t/01app.t @@ -23,8 +23,8 @@ is( scalar $tradition->witnesses, 13, "Found all witnesses" ); ok( $tradition->collation, "Tradition has a collation" ); my $c = $tradition->collation; -is( scalar $c->readings, 319, "Collation has all readings" ); -is( scalar $c->paths, 375, "Collation has all paths" ); +is( scalar $c->readings, 311, "Collation has all readings" ); +is( scalar $c->paths, 361, "Collation has all paths" ); is( scalar $c->relationships, 0, "Collation has all relationships" ); done_testing; \ No newline at end of file diff --git a/t/text_tradition_collation.t b/t/text_tradition_collation.t index bb283fa..20ac93e 100644 --- a/t/text_tradition_collation.t +++ b/t/text_tradition_collation.t @@ -10,6 +10,44 @@ $| = 1; { use Text::Tradition; +my $READINGS = 311; +my $PATHS = 361; + +my $datafile = 't/data/florilegium_tei_ps.xml'; +my $tradition = Text::Tradition->new( 'input' => 'TEI', + 'name' => 'test0', + 'file' => $datafile, + 'linear' => 1 ); + +ok( $tradition, "Got a tradition object" ); +is( scalar $tradition->witnesses, 13, "Found all witnesses" ); +ok( $tradition->collation, "Tradition has a collation" ); + +my $c = $tradition->collation; +is( scalar $c->readings, $READINGS, "Collation has all readings" ); +is( scalar $c->paths, $PATHS, "Collation has all paths" ); +is( scalar $c->relationships, 0, "Collation has all relationships" ); + +# Add a few relationships +$c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } ); +$c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } ); +$c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } ); + +# Now write it to GraphML and parse it again. + +my $graphml = $c->as_graphml; +my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml ); +is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" ); +is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" ); +is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" ); +} + + + +# =begin testing +{ +use Text::Tradition; + my $cxfile = 't/data/Collatex-16.xml'; my $t = Text::Tradition->new( 'name' => 'inline', diff --git a/t/text_tradition_parser_tei.t b/t/text_tradition_parser_tei.t index df9cb3f..2fb33a8 100644 --- a/t/text_tradition_parser_tei.t +++ b/t/text_tradition_parser_tei.t @@ -22,8 +22,8 @@ my $t = Text::Tradition->new( is( ref( $t ), 'Text::Tradition', "Parsed parallel-segmentation TEI" ); if( $t ) { - is( scalar $t->collation->readings, 319, "Collation has all readings" ); - is( scalar $t->collation->paths, 375, "Collation has all paths" ); + is( scalar $t->collation->readings, 311, "Collation has all readings" ); + is( scalar $t->collation->paths, 361, "Collation has all paths" ); } }