sub related_readings {
my( $self, $reading, $colocated ) = @_;
- $reading = $reading->id
- if ref( $reading ) eq 'Text::Tradition::Collation::Reading';
+ my $return_object;
+ if( ref( $reading ) eq 'Text::Tradition::Collation::Reading' ) {
+ $reading = $reading->id;
+ $return_object = 1;
+ print STDERR "Returning related objects\n";
+ } else {
+ print STDERR "Returning related object names\n";
+ }
my @related = $self->relations->all_reachable( $reading );
if( $colocated ) {
my @colo = grep { $self->relations->has_edge_attribute( $reading, $_, 'colocated' ) } @related;
- return @colo;
- } else {
- return @related;
- }
+ @related = @colo;
+ }
+ return $return_object ? map { $self->reading( $_ ) } @related : @related;
}
=head2 Output method(s)
is( ref( $t ), 'Text::Tradition', "Parsed our own GraphML" );
if( $t ) {
is( scalar $t->collation->readings, 26, "Collation has all readings" );
- is( scalar $t->collation->paths, 49, "Collation has all paths" );
+ is( scalar $t->collation->paths, 32, "Collation has all paths" );
is( scalar $t->witnesses, 3, "Collation has all witnesses" );
# Check an 'identical' node
my $transposed = $t->collation->reading( 'n15' );
- ok( $transposed->has_primary, "Reading links to transposed primary" );
- is( $transposed->primary->name, 'n17', "Correct transposition link" );
+ my @related = $transposed->related_readings;
+ is( scalar @related, 1, "Reading links to transposed version" );
+ is( $related[0]->id, 'n17', "Correct transposition link" );
}
=end testing
# If we are in a lacuna already, drop this node.
# Otherwise make a lacuna node and drop this node.
unless( $last_rdg->is_lacuna ) {
- my $l = $c->add_lacuna( $rdg->name );
- $l->rank( $rdg->rank );
+ my $l = $c->add_reading( {
+ 'collation' => $c,
+ 'id' => $rdg->name,
+ 'is_lacuna' => 1,
+ } );
push( @$new_p, $l );
$last_rdg = $l;
}
}
my $ctr = 1;
foreach my $w ( keys %unique ) {
- my $r = $collation->add_reading( "$index,$ctr" );
- $ctr++;
- $r->rank( $index );
- $r->text( $w );
+ my $rargs = {
+ 'collation' => $collation,
+ 'id' => "$index,$ctr",
+ 'rank' => $index,
+ 'text' => $w,
+ };
+ my $r = $collation->add_reading( $rargs );
$unique{$w} = $r;
+ $ctr++;
}
return \%unique;
}
is( ref( $t ), 'Text::Tradition', "Parsed our own GraphML" );
if( $t ) {
is( scalar $t->collation->readings, 26, "Collation has all readings" );
- is( scalar $t->collation->paths, 49, "Collation has all paths" );
+ is( scalar $t->collation->paths, 32, "Collation has all paths" );
is( scalar $t->witnesses, 3, "Collation has all witnesses" );
# Check an 'identical' node
my $transposed = $t->collation->reading( 'n15' );
- ok( $transposed->has_primary, "Reading links to transposed primary" );
- is( $transposed->primary->name, 'n17', "Correct transposition link" );
+ my @related = $transposed->related_readings;
+ is( scalar @related, 1, "Reading links to transposed version" );
+ is( $related[0]->id, 'n17', "Correct transposition link" );
}
}