CollateX: no ranks if nonlinear
[scpubgit/stemmatology.git] / lib / Text / Tradition / Analysis.pm
index 3b8888b..f4605ed 100644 (file)
@@ -9,7 +9,10 @@ sub new {
        my( $class, $args ) = @_;
        my $self = {};
        bless( $self, $class ); 
-       $self->run_analysis( $args->{'file'}, $args->{'stemmadot'} );
+       $self->{'data'} = [];
+       foreach my $t ( @{$args->{'traditions'}} ) {
+           $self->run_analysis( $t->{'file'}, $t->{'stemmadot'} );
+       }
        return $self;
 }
 
@@ -18,6 +21,7 @@ sub run_analysis {
        # What we will return
        my $svg;
        my $variants = [];
+       my $data = {};
        
        # Read in the file and stemma   
        my $tradition = Text::Tradition->new( 
@@ -25,17 +29,15 @@ sub run_analysis {
                'file'   => $file,
                'linear' => 1,
                );
-       $self->{'title'} = $tradition->name;
+       $data->{'title'} = $tradition->name;
        
        my $stemma = Text::Tradition::Stemma->new(
                'collation' => $tradition->collation,
                'dot' => $stemmadot,
                );
        # We will return the stemma picture
-       $svg = $stemma->as_svg;
-       ### DIRTY HACK
-       $svg =~ s/transform=\"scale\(1 1\)/transform=\"scale\(0.7 0.7\)/;
-       $self->{'svg'} = $svg;
+       $svg = $stemma->as_svg( { size => "8,7.5" } );;
+       $data->{'svg'} = $svg;
        
        # We have the collation, so get the alignment table with witnesses in rows.
        # Also return the reading objects in the table, rather than just the words.
@@ -100,6 +102,7 @@ sub run_analysis {
                # For all the groups with more than one member, collect the list of all
                # contiguous vertices needed to connect them.
                # TODO: deal with a.c. reading logic
+               $DB::single = 1 if $rank == 25;
                my $variant_row = analyze_variant_location( $group_readings, $groups, 
                    $stemma->apsp, $lacunose );
                $variant_row->{'id'} = $rank;
@@ -131,10 +134,11 @@ sub run_analysis {
        }
        
        # Populate self with our analysis data.
-       $self->{'variants'} = $variants;
-       $self->{'variant_count'} = $total;
-       $self->{'conflict_count'} = $conflicts;
-       $self->{'genealogical_count'} = $genealogical;
+       $data->{'variants'} = $variants;
+       $data->{'variant_count'} = $total;
+       $data->{'conflict_count'} = $conflicts;
+       $data->{'genealogical_count'} = $genealogical;
+       push( @{$self->{'data'}}, $data );
 }
 
 # variant_row -> genealogical
@@ -147,10 +151,14 @@ sub analyze_variant_location {
     my %missing;
     map { $missing{$_} = 1 } @$lacunose;
     my $variant_row = { 'readings' => [] };
+    # Mark each ms as in its own group, first.
+    foreach my $g ( @$groups ) {
+        my $gst = wit_stringify( $g );
+        map { $contig{$_} = $gst } @$g;
+    }
     foreach my $g ( sort { scalar @$b <=> scalar @$a } @$groups ) {
         my @members = @$g;
         my $gst = wit_stringify( $g ); # $gst is now the name of this group.
-        map { $contig{$_} = $gst } @members; # All members are in this group.
         while( @members ) {
             # Gather the list of vertices that are needed to join all members.
             my $curr = pop @members;