From: tla Date: Tue, 21 Jan 2014 15:02:59 +0000 (+0100) Subject: prevent merge_readings from causing witness loops X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e4f00901956fd5684b42b3ec39c1613d43688d72;p=scpubgit%2Fstemmatology.git prevent merge_readings from causing witness loops --- diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index 904d39d..b4489f2 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -357,6 +357,22 @@ sub merge_readings { || $del_obj eq $self->start || $del_obj eq $self->end ); throw( "Cannot combine text of meta readings" ) if $combine; } + # We can only merge readings in a linear graph if: + # - they are contiguous with only one edge between them, OR + # - they are at equivalent ranks in the graph. + if( $self->linear ) { + my @delpred = $del_obj->predecessors; + my @keptsuc = $kept_obj->successors; + unless ( @delpred == 1 && $delpred[0] eq $kept_obj + && @keptsuc == 1 && $keptsuc[0] eq $del_obj ) { + my( $is_ok, $msg ) = $self->relations->relationship_valid( + $kept_obj, $del_obj, 'collated' ); + unless( $is_ok ) { + throw( "Readings $kept_obj and $del_obj can be neither concatenated nor collated" ); + } + } + } + # We only need the IDs for adding paths to the graph, not the reading # objects themselves. my $kept = $kept_obj->id;