From: Tara L Andrews Date: Fri, 2 Mar 2012 18:20:15 +0000 (+0100) Subject: try not to let collations interfere with relationship mapping X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=778251a62300cb4b18914b845c418bf27f2df6b8;p=scpubgit%2Fstemmatology.git try not to let collations interfere with relationship mapping --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index 2f8784c..d8b06e2 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -351,8 +351,12 @@ sub relationship_valid { # Otherwise, first make a lookup table of all the # readings related to either the source or the target. my @proposed_related = ( $source, $target ); - push( @proposed_related, $self->related_readings( $source, 'colocated' ) ); - push( @proposed_related, $self->related_readings( $target, 'colocated' ) ); + # Drop the collation links of source and target, unless we want to + # add a collation relationship. + foreach my $r ( ( $source, $target ) ) { + $self->_drop_collations( $r ) unless $rel eq 'collated'; + push( @proposed_related, $self->related_readings( $r, 'colocated' ) ); + } my %pr_ids; map { $pr_ids{ $_ } = 1 } @proposed_related; @@ -376,6 +380,15 @@ sub relationship_valid { } } +sub _drop_collations { + my( $self, $reading ) = @_; + foreach my $n ( $self->graph->neighbors( $reading ) ) { + if( $self->get_relationship( $reading, $n )->type eq 'collated' ) { + $self->del_relationship( $reading, $n ); + } + } +} + =head2 related_readings( $reading, $filter ) Returns a list of readings that are connected via relationship links to $reading.