=over
-=item * collation - The collation with which the stemma is associated.
-
=item * dot - A filehandle open to a DOT representation of the stemma graph.
=back
=begin testing
-use Text::Tradition::Collation;
use TryCatch;
use_ok( 'Text::Tradition::Stemma' );
-# Placeholder collation to use in tests
-my $c = Text::Tradition::Collation->new();
-
# Try to create a bad graph
my $baddotfh;
open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
try {
- my $stemma = Text::Tradition::Stemma->new( collation => $c, dot => $baddotfh );
+ my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
ok( 0, "Created broken stemma from dotfile with syntax error" );
} catch( Text::Tradition::Error $e ) {
like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
my $dotfh;
open( $dotfh, 't/data/florilegium.dot' ) or die "Could not open test dotfile";
binmode( $dotfh, ':utf8' );
-my $stemma = Text::Tradition::Stemma->new( collation => $c, dot => $dotfh );
+my $stemma = Text::Tradition::Stemma->new( dot => $dotfh );
is( ref( $stemma ), 'Text::Tradition::Stemma', "Created stemma from good dotfile" );
is( scalar $stemma->witnesses, 13, "Found correct number of extant witnesses" );
is( scalar $stemma->hypotheticals, 8, "Found correct number of extant hypotheticals" );
has collation => (
is => 'ro',
isa => 'Text::Tradition::Collation',
- required => 1,
+ clearer => 'clear_collation',
weak_ref => 1,
);
=cut
sub situation_graph {
- my( $self, $extant, $layerwits ) = @_;
+ my( $self, $extant, $layerwits, $layerlabel ) = @_;
my $graph = $self->graph->copy;
foreach my $vertex ( $graph->vertices ) {
# as an ancestor of the 'main' witness, and otherwise with the same parent/
# child links as its main analogue.
# TOOD Handle case where B is copied from A but corrected from C
- my $aclabel = $self->collation->ac_label;
+ $layerlabel = ' (a.c.)' unless $layerlabel;
foreach my $lw ( @$layerwits ) {
# Add the layered witness and set it with the same attributes as
# its 'main' analogue
throw( "Cannot add a layer to a hypothetical witness $lw" )
unless $graph->get_vertex_attribute( $lw, 'class' ) eq 'extant';
- my $lwac = $lw . $aclabel;
+ my $lwac = $lw . $layerlabel;
$graph->add_vertex( $lwac );
$graph->set_vertex_attributes( $lwac,
$graph->get_vertex_attributes( $lw ) );
foreach my $v ( $graph->predecessors( $lw ) ) {
next if $v eq $lwac; # Don't add a loop
$graph->add_edge( $v, $lwac );
- $graph->add_edge( $v.$aclabel, $lwac )
- if $graph->has_vertex( $v.$aclabel );
+ $graph->add_edge( $v.$layerlabel, $lwac )
+ if $graph->has_vertex( $v.$layerlabel );
}
foreach my $v ( $graph->successors( $lw ) ) {
next if $v eq $lwac; # but this shouldn't occur
$graph->add_edge( $lwac, $v );
- $graph->add_edge( $lwac, $v.$aclabel )
- if $graph->has_vertex( $v.$aclabel );
+ $graph->add_edge( $lwac, $v.$layerlabel )
+ if $graph->has_vertex( $v.$layerlabel );
}
}
return $graph;
# =begin testing
{
-use Text::Tradition::Collation;
use TryCatch;
use_ok( 'Text::Tradition::Stemma' );
-# Placeholder collation to use in tests
-my $c = Text::Tradition::Collation->new();
-
# Try to create a bad graph
my $baddotfh;
open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
try {
- my $stemma = Text::Tradition::Stemma->new( collation => $c, dot => $baddotfh );
+ my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
ok( 0, "Created broken stemma from dotfile with syntax error" );
} catch( Text::Tradition::Error $e ) {
like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
my $dotfh;
open( $dotfh, 't/data/florilegium.dot' ) or die "Could not open test dotfile";
binmode( $dotfh, ':utf8' );
-my $stemma = Text::Tradition::Stemma->new( collation => $c, dot => $dotfh );
+my $stemma = Text::Tradition::Stemma->new( dot => $dotfh );
is( ref( $stemma ), 'Text::Tradition::Stemma', "Created stemma from good dotfile" );
is( scalar $stemma->witnesses, 13, "Found correct number of extant witnesses" );
is( scalar $stemma->hypotheticals, 8, "Found correct number of extant hypotheticals" );