try not to let collations interfere with relationship mapping
Tara L Andrews [Fri, 2 Mar 2012 18:20:15 +0000 (19:20 +0100)]
lib/Text/Tradition/Collation/RelationshipStore.pm

index 2f8784c..d8b06e2 100644 (file)
@@ -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.