X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=blobdiff_plain;f=lib%2FText%2FTradition%2FCollation%2FRelationshipStore.pm;fp=lib%2FText%2FTradition%2FCollation%2FRelationshipStore.pm;h=d3ca9bf31f5dd85e3a0f2b68e3dca9d2d05b0fbc;hp=aeb8b7f8e1302f52ad2b991201181b6e977d7e23;hb=9a7df25a0901fa0a67fed374e6051f0f85fed3a2;hpb=fc5c4949b38572067ab389afa8c1cafec2b5dbd0 diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index aeb8b7f..d3ca9bf 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -196,18 +196,9 @@ sub create { } } - # Check to see if a nonlocal relationship is defined for the two readings - $rel = $self->scoped_relationship( $options->{'reading_a'}, - $options->{'reading_b'} ); - if( $rel && $rel->type eq $options->{'type'} ) { - return $rel; - } elsif( $rel ) { - throw( sprintf( "Relationship of type %s with scope %s already defined for readings %s and %s", $rel->type, $rel->scope, $options->{'reading_a'}, $options->{'reading_b'} ) ); - } else { - $rel = Text::Tradition::Collation::Relationship->new( $options ); - $self->add_scoped_relationship( $rel ) if $rel->nonlocal; - return $rel; - } + $rel = Text::Tradition::Collation::Relationship->new( $options ); + $self->add_scoped_relationship( $rel ) if $rel->nonlocal; + return $rel; } =head2 add_scoped_relationship( $rel ) @@ -435,8 +426,10 @@ sub add_relationship { my $otherrel = $self->scoped_relationship( $rdga, $rdgb ); if( $otherrel && $otherrel->type eq $options->{type} && $otherrel->scope eq $options->{scope} ) { - warn "Applying existing scoped relationship"; + warn "Applying existing scoped relationship for $rdga / $rdgb"; $relationship = $otherrel; + } elsif( $otherrel ) { + throw( "Conflicting scoped relationship for $rdga / $rdgb at $source / $target" ); } } $relationship = $self->create( $options ) unless $relationship; # Will throw on error @@ -717,6 +710,9 @@ sub related_readings { # Backwards compat if( $filter eq 'colocated' ) { $filter = sub { $_[0]->colocated }; + } elsif( !ref( $filter ) ) { + my $type = $filter; + $filter = sub { $_[0]->type eq $type }; } my %found = ( $reading => 1 ); my $check = [ $reading ];