From: Tara L Andrews Date: Fri, 6 Apr 2012 20:36:40 +0000 (+0200) Subject: make path labels do the right thing with a.c. witnesses X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f9f05e8fb939d42164ee503a9964fc56caef757;p=scpubgit%2Fstemmatology.git make path labels do the right thing with a.c. witnesses --- diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 68b2adf..6357a6f 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -783,15 +783,34 @@ sub path_witnesses { return @wits; } +# Helper function. Make a display label for the given witnesses, showing a.c. +# witnesses only where the main witness is not also in the list. sub _path_display_label { my $self = shift; - my @wits = sort @_; + my %wits; + map { $wits{$_} = 1 } @_; + + # If an a.c. wit is listed, remove it if the main wit is also listed. + # Otherwise keep it for explicit listing. + my $aclabel = $self->ac_label; + my @disp_ac; + foreach my $w ( sort keys %wits ) { + if( $w =~ /^(.*)\Q$aclabel\E$/ ) { + if( exists $wits{$1} ) { + delete $wits{$w}; + } else { + push( @disp_ac, $w ); + } + } + } + + # See if we are in a majority situation. my $maj = scalar( $self->tradition->witnesses ) * 0.6; - if( scalar @wits > $maj ) { - # TODO break out a.c. wits - return 'majority'; + if( scalar keys %wits > $maj ) { + unshift( @disp_ac, 'majority' ); + return join( ', ', @disp_ac ); } else { - return join( ', ', @wits ); + return join( ', ', sort keys %wits ); } }