calculate common readings when we parse
[scpubgit/stemmatology.git] / lib / Text / Tradition / Parser / TEI.pm
index 6b9734f..3d5fd03 100644 (file)
@@ -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, 374, "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
@@ -160,7 +160,6 @@ sub parse {
         }
         # See if we need to make an a.c. version of the witness.
         if( exists $app_ac->{$sig} ) {
-               $DB::single = 1;
             my @uncorrected;
             push( @uncorrected, @real_sequence );
             foreach my $app ( keys %{$app_ac->{$sig}} ) {
@@ -172,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 );
         }
@@ -192,6 +188,13 @@ sub parse {
     # Now that we have ranks, see if we have distinct nodes with identical
     # text and identical rank that can be merged.
     $tradition->collation->flatten_ranks();
+    
+    # And now that we've done that, calculate the common nodes.
+    $tradition->collation->calculate_common_readings();
+    
+    # Save the text for each witness so that we can ensure consistency
+    # later on
+       $tradition->collation->text_from_paths();       
 }
 
 sub _clean_sequence {