From: Tara L Andrews Date: Fri, 24 Feb 2012 01:17:15 +0000 (+0100) Subject: fix small logic bug in pre-existing scoped relationship detection X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ac5e75094ef0e62b940ab89b0c12d9a3287ff83;p=scpubgit%2Fstemmatology.git fix small logic bug in pre-existing scoped relationship detection --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index 0f48552..47d384e 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -228,21 +228,23 @@ sub add_relationship { $options->{'reading_b'} = $target_rdg->text; $options->{'orig_a'} = $source; $options->{'orig_b'} = $target; - $relationship = $self->create( $options ); # Will throw on error + if( $options->{'scope'} ne 'local' ) { + # Is there a relationship with this a & b already? + my $otherrel = $self->scoped_relationship( $options->{reading_a}, + $options->{reading_b} ); + if( $otherrel && $otherrel->type eq $options->{type} + && $otherrel->scope eq $options->{scope} ) { + warn "Applying existing scoped relationship"; + $relationship = $otherrel; + } + } + $relationship = $self->create( $options ) unless $relationship; # Will throw on error } # Find all the pairs for which we need to set the relationship. my @vectors = ( [ $source, $target ] ); if( $relationship->colocated && $relationship->nonlocal && !$thispaironly ) { - # Is there a relationship with this a & b already? - my $otherrel = $self->scoped_relationship( $relationship->reading_a, - $relationship->reading_b ); - if( $otherrel && $otherrel->type eq $relationship->type - && $otherrel->scope eq $relationship->scope ) { - warn "Applying existing scoped relationship"; - $relationship = $otherrel; - } my $c = $self->collation; # Set the same relationship everywhere we can, throughout the graph. my @identical_readings = grep { $_->text eq $relationship->reading_a }