is( scalar @v1, 1, "Deleted first relationship" );
@v2 = $c->del_relationship( 'n8', 'n13' );
is( scalar @v2, 2, "Deleted second global relationship" );
-try {
- my @v3 = $c->del_relationship( 'n1', 'n2' );
- ok( 0, "Should have errored on non-existent relationship" );
-} catch( Text::Tradition::Error $e ) {
- like( $e->message, qr/No relationship defined/, "Attempt to delete non-existent relationship errored" );
-}
+my @v3 = $c->del_relationship( 'n1', 'n2' );
+is( scalar @v3, 0, "Nothing deleted on non-existent relationship" );
=end testing
sub del_relationship {
my( $self, $source, $target ) = @_;
my $rel = $self->get_relationship( $source, $target );
- throw( "No relationship defined between $source and $target" ) unless $rel;
+ return () unless $rel; # Nothing to delete; return an empty set.
my @vectors = ( [ $source, $target ] );
$self->_remove_relationship( $source, $target );
if( $rel->nonlocal ) {
--- /dev/null
+#!/usr/bin/env perl
+
+use lib 'lib';
+use strict;
+use warnings;
+use Text::Tradition::Directory;
+
+binmode STDERR, ':utf8';
+binmode STDOUT, ':utf8';
+eval { no warnings; binmode $DB::OUT, ':utf8' };
+
+my( $dsn, $user, $pass ) = @ARGV;
+
+my $connect_args = { dsn => $dsn };
+$connect_args->{'extra_args'} = { user => $user, password => $pass }
+ if $user && $pass;
+my $dir = Text::Tradition::Directory->new( $connect_args );
+
+foreach my $text ( $dir->traditionlist ) {
+ my $id = $text->{'id'};
+ my $scope = $dir->new_scope;
+ my $tradition = $dir->lookup( $id );
+ print STDERR "Processing tradition " . $tradition->name . "\n";
+ my $c = $tradition->collation;
+ foreach my $rank ( 1 .. $c->end->rank - 1 ) {
+ my @readings = $c->readings_at_rank( $rank );
+ while( @readings ) {
+ my $r = pop @readings;
+ next if $r->is_meta;
+ my @orthmatch = grep { lc( $r->text ) eq lc( $_->text ) } @readings;
+ foreach my $om ( @orthmatch ) {
+ unless( $c->get_relationship( $r, $om ) ) {
+ print STDERR sprintf( "Adding orthographic link for %s / %s\n",
+ $r->text, $om->text );
+ $DB::single = 1;
+ $c->add_relationship( $r, $om,
+ { 'type' => 'orthographic', 'scope' => 'global' } );
+ }
+ }
+ }
+ }
+ $dir->save( $tradition );
+}
+
+print STDERR "Done\n";
my @all_relations;
foreach my $p ( @pairs ) {
my $relobj = $collation->relations->get_relationship( @$p );
+ next if $relobj->type eq 'collated'; # Don't show these
my $relhash = { source => $p->[0], target => $p->[1],
type => $relobj->type, scope => $relobj->scope };
$relhash->{'note'} = $relobj->annotation if $relobj->has_annotation;
is( scalar @v1, 1, "Deleted first relationship" );
@v2 = $c->del_relationship( 'n8', 'n13' );
is( scalar @v2, 2, "Deleted second global relationship" );
-try {
- my @v3 = $c->del_relationship( 'n1', 'n2' );
- ok( 0, "Should have errored on non-existent relationship" );
-} catch( Text::Tradition::Error $e ) {
- like( $e->message, qr/No relationship defined/, "Attempt to delete non-existent relationship errored" );
-}
+my @v3 = $c->del_relationship( 'n1', 'n2' );
+is( scalar @v3, 0, "Nothing deleted on non-existent relationship" );
}