}
}
- # 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 )
"Relationship link prevented for a meta reading" );
}
+# Test 1.4: try to break a relationship near a meta reading
+$c1->add_relationship( 'r7.6', 'r7.3', { type => 'orthographic' } );
+try {
+ $c1->del_relationship( 'r7.6', 'r7.7' );
+ $c1->del_relationship( 'r7.6', 'r7.3' );
+ ok( 1, "Relationship broken with a meta reading as neighbor" );
+} catch {
+ ok( 0, "Relationship deletion failed with a meta reading as neighbor" );
+}
+
# Test 2.1: try to equate nodes that are prevented with a real intermediate
# equivalence
my $t2;
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
# 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 ];
my( $self, $source, $target ) = @_;
my $seq = $self->equivalence( $source );
my $teq = $self->equivalence( $target );
- return unless $seq && $teq;
$self->equivalence_graph->add_edge( $seq, $teq );
}
my $c = $self->collation;
foreach my $rdg ( @$newmembers ) {
foreach my $rp ( $c->sequence->predecessors( $rdg ) ) {
+ next unless $self->equivalence( $rp );
$self->equivalence_graph->add_edge( $self->equivalence( $rp ), $newgroup );
}
foreach my $rs ( $c->sequence->successors( $rdg ) ) {
+ next unless $self->equivalence( $rs );
$self->equivalence_graph->add_edge( $newgroup, $self->equivalence( $rs ) );
}
}
my( %old_pred, %old_succ );
foreach my $rdg ( @$oldmembers ) {
foreach my $rp ( $c->sequence->predecessors( $rdg ) ) {
+ next unless $self->equivalence( $rp );
$old_pred{$self->equivalence( $rp )} = 1;
}
foreach my $rs ( $c->sequence->successors( $rdg ) ) {
+ next unless $self->equivalence( $rs );
$old_succ{$self->equivalence( $rs )} = 1;
}
}
$self->_clear_equivalence;
$self->_clear_eqreadings;
+ $self->collation->tradition->_init_done(0);
# Add the readings
foreach my $r ( $self->collation->readings ) {
my $rid = $r->id;
next unless $relobj && $relobj->colocated;
$self->_make_equivalence( @$rel );
}
+ $self->collation->tradition->_init_done(1);
}
=head2 equivalence_ranks