Stemma.pm

filter: Statementstmt 76.8% 133 / 173 Branchbran 50.0% 26 / 52 Conditioncond 38.4% 5 / 13 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 95.8% 23 / 24 Podpod 84.6% 11 / 13 totaltotal 70.5% 199 / 282 CC 44 SCAR 28.1
CC
44
Cov
69%
situation_graph
60.5
editable
12.0
rename_witnesses
8.8
CRAP 16.7
« StemmaUtil.pm ↑ Summary Analysis/Result.pm »
1 package Text::Tradition::Stemma;
2  
3 5 ▶use Encode qw( decode_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Graph::Reader::Dot;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use IPC::Run qw/ run binary /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Text::Tradition::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Text::Tradition::StemmaUtil qw/ read_graph editable_graph display_graph
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 parse_newick /;
11 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Text::Tradition::Stemma - a representation of a I<stemma codicum> for a Text::Tradition
16  
17 =head1 SYNOPSIS
18  
19 use Text::Tradition;
20 my $t = Text::Tradition->new(
21 'name' => 'this is a text',
22 'input' => 'TEI',
23 'file' => '/path/to/tei_parallel_seg_file.xml' );
24  
25 my $s = $tradition->add_stemma( dotfile => '/path/to/stemma.dot' );
26
27 =head1 DESCRIPTION
28  
29 Text::Tradition is a library for representation and analysis of collated
30 texts, particularly medieval ones. The Stemma is a representation of the
31 copying relationships between the witnesses in a Tradition, modelled with
32 a connected rooted directed acyclic graph (CRDAG).
33  
34 =head1 DOT SYNTAX
35  
36 The easiest way to define a stemma is to use a special form of the 'dot'
37 syntax of GraphViz.
38  
39 Each stemma opens with the line
40  
41 digraph "Name of Stemma" {
42
43 and continues with a list of all manuscript witnesses in the stemma, whether
44 extant witnesses or missing archetypes or hyparchetypes. Each of these is
45 listed by its sigil on its own line, e.g.:
46  
47 alpha [ class=hypothetical ]
48 1 [ class=hypothetical,label=* ]
49 Ms4 [ class=extant ]
50
51 Extant witnesses are listed with class=extant; missing or postulated witnesses
52 are listed with class=hypothetical. Anonymous hyparchetypes must be given a
53 unique name or number, but can be represented as anonymous with the addition
54 of 'label=*' to their lines. Greek letters or other special characters may be
55 used as names, but they must always be wrapped in double quotes.
56  
57 Links between manuscripts are then listed with arrow notation, as below. These
58 lines show the direction of copying, one step at a time, for the entire stemma.
59  
60 alpha -> 1
61 1 -> Ms4
62
63 The final line in the definition should be the closing brace:
64  
65 }
66
67 Thus for a set of extant manuscripts A, B, and C, where A and B were copied
68 from the archetype O and C was copied from B, the definition would be:
69  
70 digraph "Test stemma 1" {
71 O [ class=hypothetical]
72 A [ class=extant ]
73 B [ class=extant ]
74 C [ class=extant ]
75 O -> A
76 O -> B
77 B -> C
78 }
79  
80 =head1 CONSTRUCTOR
81  
82 =head2 new
83  
84 The constructor. This should generally be called from Text::Tradition, but
85 if called directly it takes the following options:
86  
87 =over
88  
89 =item * dot - A filehandle open to a DOT representation of the stemma graph.
90  
91 =item * graph - If no DOT specification is given, you can pass a Graph object
92 instead. The vertices of the graph should have an attribute 'class' set to
93 either of the values 'extant' or 'hypothetical'.
94  
95 =item * is_undirected - If the graph specification (or graph object) is for an
96 undirected graph (e.g. a phylogenetic tree), this should be set.
97  
98 =back
99  
100 =begin testing
101  
102 use TryCatch;
103  
104 use_ok( 'Text::Tradition::Stemma' );
105  
106 # Try to create a bad graph
107 try {
108 my $stemma = Text::Tradition::Stemma->new( dotfile => 't/data/besoin_bad.dot' );
109 ok( 0, "Created broken stemma from dotfile with syntax error" );
110 } catch( Text::Tradition::Error $e ) {
111 like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
112 }
113  
114 # Create a good graph
115 my $stemma = Text::Tradition::Stemma->new( dotfile => 't/data/florilegium.dot' );
116 is( ref( $stemma ), 'Text::Tradition::Stemma', "Created stemma from good dotfile" );
117 is( scalar $stemma->witnesses, 13, "Found correct number of extant witnesses" );
118 is( scalar $stemma->hypotheticals, 8, "Found correct number of extant hypotheticals" );
119 ok( $stemma->has_identifier, "Stemma identifier was found in dot" );
120 is( $stemma->identifier, 'Coislinianum lineage', "Correct stemma identifier was found in dot" );
121 my $found_unicode_sigil;
122 foreach my $h ( $stemma->hypotheticals ) {
123 $found_unicode_sigil = 1 if $h eq "\x{3b1}";
124 }
125 ok( $found_unicode_sigil, "Found a correctly encoded Unicode sigil" );
126  
127 # Create an undirected graph
128 my $udstemma = Text::Tradition::Stemma->new( dotfile => 't/data/besoin_undirected.dot' );
129 is( ref( $udstemma ), 'Text::Tradition::Stemma', "Created stemma from undirected dotfile" );
130 is( scalar $udstemma->witnesses, 13, "Found correct number of extant witnesses" );
131 is( scalar $udstemma->hypotheticals, 12, "Found correct number of hypotheticals" );
132 ok( $udstemma->is_undirected, "Stemma was recorded as undirected" );
133 is( $udstemma->identifier, "RHM stemma", "Undirected graph retained its name" );
134  
135 =end testing
136  
137 =cut
138  
139 5 has collation => (
140 is => 'ro',
141 isa => 'Text::Tradition::Collation',
142 clearer => 'clear_collation', # interim measure to remove refs in DB
143 weak_ref => 1,
144 );
145  
146 5 has graph => (
147 is => 'rw',
148 isa => 'Graph',
149 predicate => 'has_graph',
150 );
151
152 5 has identifier => (
153 is => 'ro',
154 isa => 'Str',
155 writer => 'set_identifier',
156 predicate => 'has_identifier',
157 );
158
159 5 has from_jobid => (
160 is => 'ro',
161 isa => 'Str',
162 predicate => 'came_from_jobid',
163 writer => '_set_from_jobid',
164 );
165
166 7 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.3
Pod undocumented
167 7 my( $self, $args ) = @_;
168 # If we have been handed a dotfile, initialize it into a graph.
169 7 my $dotstring;
170 7 ▶ if( exists $args->{'dot'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args->{'dot'}) { } 0 7 7
elsif (exists $args->{'dotfile'}) { } 6 1 7
171 0 $dotstring = $args->{'dot'};
172 } elsif( exists $args->{'dotfile'} ) {
173 # Read the file into a string.
174 6 my @dotlines;
175 open( DOTFH, $args->{'dotfile'} )
176 6 ▶ or throw( "Could not read specified dot file " . $args->{'dotfile'} );
Branch: 1 branch
BranchTrueFalseTotal
open DOTFH, $args->{"dotfile"} or throw('Could not read specified dot file ' . $args->{"dotfile"}) 6 0 6
177 6 binmode( DOTFH, ':encoding(UTF-8)' );
178 6 @dotlines = <DOTFH>;
179 6 close DOTFH;
180 6 $dotstring = join( '', @dotlines );
181 }
182 7 ▶ $self->_graph_from_dot( $dotstring ) if $dotstring;
Branch: 1 branch
BranchTrueFalseTotal
if $dotstring 6 1 7
183 }
184  
185 6170 ▶before 'graph' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.7
186 6170 my $self = shift;
187 6170 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 6162 6170
188 # Make sure all unclassed graph nodes are marked extant.
189 8 my $g = $_[0];
190 8 ▶ throw( "Cannot set graph to a non-Graph object" )
Branch: 1 branch
BranchTrueFalseTotal
unless $g->isa("Graph") 0 8 8
191 unless $g->isa( 'Graph' );
192 8 foreach my $v ( $g->vertices ) {
193 105 ▶ unless( $g->has_vertex_attribute( $v, 'class' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($g->has_vertex_attribute($v, "class")) 0 105 105
194 0 $g->set_vertex_attribute( $v, 'class', 'extant' );
195 }
196 }
197 }
198 5 };
199  
200 8 ▶sub _graph_from_dot {
Subroutine _graph_from_dot: called CC=2 SCAR=7.0
201 8 my( $self, $dotstring ) = @_;
202 8 my $graph = read_graph( $dotstring );
203
204 ## HORRIBLE HACK but there is no API access to graph attributes!
205 7 ▶ my $graph_id = $graph->has_graph_attribute( 'name' )
Branch: 1 branch
BranchTrueFalseTotal
$graph->has_graph_attribute('name') ? : 7 0 7
206 ? $graph->get_graph_attribute( 'name' ) : 'stemma';
207 7 $self->graph( $graph );
208 7 $self->set_identifier( $graph_id );
209 }
210  
211 4 ▶sub is_undirected {
Subroutine is_undirected: called CC=2 SCAR=7.1
Pod documented
212 4 my( $self ) = @_;
213 4 ▶ return undef unless $self->has_graph;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_graph 0 4 4
214 4 return $self->graph->is_undirected;
215 }
216  
217 =head2 new_from_newick( $newick_string )
218  
219 A constructor that will read a Newick-format tree specification and return one
220 or more undirected Stemma objects. TODO test
221  
222 =cut
223  
224 1 ▶sub new_from_newick {
Subroutine new_from_newick: called CC=2 SCAR=6.9
Pod documented
225 1 my( $class, $nstring ) = @_;
226 1 my @stemmata;
227 1 foreach my $tree ( parse_newick( $nstring ) ) {
228 1 my $stemma = new( $class, graph => $tree );
229 1 push( @stemmata, $stemma );
230 }
231 1 return \@stemmata;
232 }
233  
234 =head2 rename_witnesses( \%namehash, $all_extant )
235  
236 Take a hash of old -> new sigil mappings, and change the names of the witnesses.
237  
238 =cut
239  
240 1 ▶sub rename_witnesses {
Subroutine rename_witnesses: called CC=7 SCAR=21.8
Pod documented
241 1 my( $self, $names, $all_extant ) = @_;
242 1 my $old = $self->graph;
243 1 my $newdot = $self->editable;
244 1 foreach my $k ( keys %$names ) {
245 13 my $v = $names->{$k};
246 13 $newdot =~ s/\b$k\b/$v/g;
247 }
248 1 $self->alter_graph( $newdot );
249 1 ▶ if( $all_extant ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_extant) { } 1 0 1
250 1 foreach my $v ( values %$names ) {
251 13 $self->graph->set_vertex_attribute( $v, 'class', 'extant' );
252 }
253 1 foreach my $v ( $self->graph->vertices ) {
254 25 ▶ unless( $self->graph->has_vertex_attribute( $v, 'class' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->graph->has_vertex_attribute($v, "class")) 0 25 25
255 0 $self->graph->set_vertex_attribute( $v, 'class', 'hypothetical' );
256 }
257 }
258 } else {
259 0 foreach my $n ( $old->vertices ) {
260 0 my $v = $names->{$n};
261 0 my $class = $old->get_vertex_attribute( $n, 'class' );
262 0 $self->graph->set_vertex_attribute( $v, 'class', $class );
263 }
264 }
265 }
266  
267 =head1 METHODS
268  
269 =head2 as_dot( \%options )
270  
271 Returns a normal dot representation of the stemma layout, suitable for rendering
272 with GraphViz. Options include:
273  
274 =over
275  
276 =item * graph - A hashref of global graph options.
277  
278 =item * node - A hashref of global node options.
279  
280 =item * edge - A hashref of global edge options.
281  
282 =back
283  
284 See the GraphViz documentation for the list of available options.
285  
286 =cut
287  
288 1 ▶sub as_dot {
Subroutine as_dot: called CC=3 SCAR=13.1
Pod documented
289 1 my( $self, $opts ) = @_;
290
291 ## See if we are including any a.c. witnesses in this graph.
292 1 my $graph = $self->graph;
293 1 ▶ if( exists $opts->{'layerwits'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"layerwits"}) 0 1 1
294 0 my $extant = {};
295 0 map { $extant->{$_} = 1 } $self->witnesses;
296 0 $graph = $self->situation_graph( $extant, $opts->{'layerwits'} );
297 }
298 1 ▶ if( $self->has_identifier ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_identifier) 1 0 1
299 1 $opts->{'name'} = $self->identifier;
300 }
301 1 return display_graph( $graph, $opts );
302 }
303  
304 =head2 alter_graph( $dotstring )
305  
306 Alters the graph of this stemma according to the definition specified
307 in $dotstring.
308  
309 =cut
310  
311 2 ▶sub alter_graph {
Subroutine alter_graph: called CC=1 SCAR=0.0
Pod documented
312 2 my( $self, $dotstring ) = @_;
313 2 $self->_graph_from_dot( $dotstring );
314 }
315  
316 =head2 editable( $opts )
317  
318 Returns a version of the graph rendered in our definition format. The
319 output separates statements with a newline; set $opts->{'linesep'} to the
320 empty string or to a space if the result is to be sent via JSON.
321  
322 If a situational version of the stemma is required, the arguments for
323 situation_graph should be passed via $opts->{'extant'} and $opts->{'layerwits'}.
324  
325 =cut
326  
327 2 ▶sub editable {
Subroutine editable: called CC=6 SCAR=24.8
Pod documented
328 2 my( $self, $opts ) = @_;
329 2 my $graph = $self->graph;
330 2 ▶ if( $self->has_identifier ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_identifier) 2 0 2
331 2 $opts->{'name'} = $self->identifier;
332 }
333 ## See if we need an editable version of a situational graph.
334 2 ▶ if( exists $opts->{'layerwits'} || exists $opts->{'extant'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"layerwits"} or exists $opts->{"extant"}) 0 2 2
Condition33%1/3
exists $opts->{"layerwits"} or exists $opts->{"extant"}
l!l&&r!l&&!r
002
MC/DC0%0/2
exists $opts->{"layerwits"} or exists $opts->{"extant"}
exists $opts->{"layerwits"} exists $opts->{"extant"}
Truth table33%1/3
A or B
A= exists $opts->{"layerwits"}B= exists $opts->{"extant"}
ABresult
1X1
011
000
335 0 ▶ my $extant = delete $opts->{'extant'} || {};
Condition0%0/2
delete $opts->{'extant'} || {}
l!l
00
MC/DC0%0/1
delete $opts->{'extant'} || {}
delete $opts->{'extant'}
Truth table0%0/2
A
A= delete $opts->{'extant'}
Aresult
11
00
336 0 ▶ my $layerwits = delete $opts->{'layerwits'} || [];
Condition0%0/2
delete $opts->{'layerwits'} || []
l!l
00
MC/DC0%0/1
delete $opts->{'layerwits'} || []
delete $opts->{'layerwits'}
Truth table0%0/2
A
A= delete $opts->{'layerwits'}
Aresult
11
00
337 0 $graph = $self->situation_graph( $extant, $layerwits );
338 }
339 2 return editable_graph( $graph, $opts );
340 }
341  
342  
343 =head2 situation_graph( $extant, $layered )
344  
345 Returns a graph which is the original stemma graph with all witnesses not
346 in the %$extant hash marked as hypothetical, and witness layers added to
347 the graph according to the list in @$layered. A layered (a.c.) witness is
348 added as a parent of its main version, and additionally shares all other
349 parents and children with that version.
350  
351 =cut
352  
353 438 ▶sub situation_graph {
Subroutine situation_graph: called CC=14 SCAR=41.0
Pod documented
354 438 my( $self, $extant, $layerwits, $layerlabel ) = @_;
355
356 438 my $graph = $self->graph->copy;
357 438 foreach my $vertex ( $graph->vertices ) {
358 # Set as extant any vertex that is extant in the stemma AND
359 # exists in the $extant hash.
360 6132 my $class = 'hypothetical';
361 6132 ▶ $class = 'extant' if exists $extant->{$vertex} && $extant->{$vertex} &&
Branch: 1 branch
BranchTrueFalseTotal
if exists $extant->{$vertex} and $extant->{$vertex} and $self->graph->get_vertex_attribute($vertex, "class") ne "hypothetical" 5427 705 6132
Condition66%4/6
exists $extant->{$vertex} and $extant->{$vertex} and $self->graph->get_vertex_attribute($vertex, "class") ne "hypothetical"
!ll&&!rl&&r
70505427
exists $extant->{$vertex} and $extant->{$vertex}
!ll&&!rl&&r
70505427
MC/DC33%1/3
exists $extant->{$vertex} and $extant->{$vertex} and $self->graph->get_vertex_attribute($vertex, "class") ne "hypothetical"
exists $extant->{$vertex} $extant->{$vertex} $self->graph->get_vertex_attribute($vertex, "class") ne "hypothetical"
Truth table50%2/4
A and B and C
A= exists $extant->{$vertex}B= $extant->{$vertex}C= $self->graph->get_vertex_attribute($vertex, "class") ne "hypothetical"
ABCresult
0XX0
10X0
1100
1111
362 $self->graph->get_vertex_attribute( $vertex, 'class' ) ne 'hypothetical';
363 6132 $graph->set_vertex_attribute( $vertex, 'class', $class );
364 }
365
366 # For each 'layered' witness in the layerwits array, add it to the graph
367 # as an ancestor of the 'main' witness, and otherwise with the same parent/
368 # child links as its main analogue.
369 # TOOD Handle case where B is copied from A but corrected from C
370 438 ▶ $layerlabel = ' (a.c.)' unless $layerlabel;
Branch: 1 branch
BranchTrueFalseTotal
unless $layerlabel 0 438 438
371 438 foreach my $lw ( @$layerwits ) {
372 # Add the layered witness and set it with the same attributes as
373 # its 'main' analogue
374 0 ▶ throw( "Cannot add a layer to a hypothetical witness $lw" )
Branch: 1 branch
BranchTrueFalseTotal
unless $graph->get_vertex_attribute($lw, "class") eq "extant" 0 0 0
375 unless $graph->get_vertex_attribute( $lw, 'class' ) eq 'extant';
376 0 my $lwac = $lw . $layerlabel;
377 0 $graph->add_vertex( $lwac );
378 0 $graph->set_vertex_attributes( $lwac,
379 $graph->get_vertex_attributes( $lw ) );
380
381 # Set it as ancestor to the main witness
382 0 $graph->add_edge( $lwac, $lw );
383
384 # Give it the same ancestors and descendants as the main witness has,
385 # bearing in mind that those ancestors and descendants might also just
386 # have had a layered witness defined.
387 0 foreach my $v ( $graph->predecessors( $lw ) ) {
388 0 ▶ next if $v eq $lwac; # Don't add a loop
Branch: 1 branch
BranchTrueFalseTotal
if $v eq $lwac 0 0 0
389 0 $graph->add_edge( $v, $lwac );
390 0 ▶ $graph->add_edge( $v.$layerlabel, $lwac )
Branch: 1 branch
BranchTrueFalseTotal
if $graph->has_vertex($v . $layerlabel) 0 0 0
391 if $graph->has_vertex( $v.$layerlabel );
392 }
393 0 foreach my $v ( $graph->successors( $lw ) ) {
394 0 ▶ next if $v eq $lwac; # but this shouldn't occur
Branch: 1 branch
BranchTrueFalseTotal
if $v eq $lwac 0 0 0
395 0 $graph->add_edge( $lwac, $v );
396 0 ▶ $graph->add_edge( $lwac, $v.$layerlabel )
Branch: 1 branch
BranchTrueFalseTotal
if $graph->has_vertex($v . $layerlabel) 0 0 0
397 if $graph->has_vertex( $v.$layerlabel );
398 }
399 }
400 438 return $graph;
401 }
402  
403 =head2 as_svg
404  
405 Returns an SVG representation of the graph, calling as_dot first.
406  
407 =cut
408  
409 0 ▶sub as_svg {
Subroutine as_svg: not called CC=2 SCAR=17.9
Pod documented
410 0 my( $self, $opts ) = @_;
411 0 my $dot = $self->as_dot( $opts );
412 0 my @cmd = ( '-Tsvg' );
413 0 ▶ unshift( @cmd, $self->is_undirected ? 'neato' : 'dot' );
Branch: 1 branch
BranchTrueFalseTotal
$self->is_undirected ? : 0 0 0
414 0 my $svg;
415 0 my $dotfile = File::Temp->new();
416 0 binmode $dotfile, ':utf8';
417 0 print $dotfile $dot;
418 0 close $dotfile;
419 0 push( @cmd, $dotfile->filename );
420 0 run( \@cmd, ">", binary(), \$svg );
421 0 return decode_utf8( $svg );
422 }
423  
424 =head2 witnesses
425  
426 Returns a list of the extant witnesses represented in the stemma.
427  
428 =cut
429  
430 7 ▶sub witnesses {
Subroutine witnesses: called CC=1 SCAR=0.0
Pod documented
431 7 my $self = shift;
432 7 my @wits = grep { $self->graph->get_vertex_attribute( $_, 'class' ) eq 'extant' }
433 $self->graph->vertices;
434 7 return @wits;
435 }
436  
437 =head2 hypotheticals
438  
439 Returns a list of the hypothetical witnesses represented in the stemma.
440  
441 =cut
442  
443 7 ▶sub hypotheticals {
Subroutine hypotheticals: called CC=1 SCAR=0.0
Pod documented
444 7 my $self = shift;
445 my @wits = grep
446 7 { $self->graph->get_vertex_attribute( $_, 'class' ) eq 'hypothetical' }
447 $self->graph->vertices;
448 7 return @wits;
449 }
450  
451 =head2 root_graph( $root_vertex )
452  
453 If the stemma graph is undirected, make it directed with $root_vertex at the root.
454 If it is directed, re-root it.
455  
456 =cut
457  
458 2 ▶sub root_graph {
Subroutine root_graph: called CC=6 SCAR=17.9
Pod documented
459 2 my( $self, $rootvertex ) = @_;
460 2 my $graph;
461 2 my $ident = $self->identifier; # will have to restore this at the end
462 2 ▶ if( $self->is_undirected ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_undirected) { } 0 2 2
463 0 $graph = $self->graph;
464 } else {
465 # Make an undirected version of this graph.
466 2 $graph = $self->graph->undirected_copy();
467 }
468 # First, ensure that the requested root is actually a vertex in the graph.
469 2 ▶ unless( $graph->has_vertex( $rootvertex ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($graph->has_vertex($rootvertex)) 1 1 2
470 1 throw( "Cannot orient graph $graph on nonexistent vertex $rootvertex" );
471 }
472
473 # Now make a directed version of the graph.
474 1 my $rooted = Graph->new();
475 1 $rooted->add_vertex( $rootvertex );
476 1 my @next = ( $rootvertex );
477 1 ▶ while( @next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@next) 4 1 5
478 4 my @children;
479 4 foreach my $v ( @next ) {
480 # Place its not-placed neighbors (ergo children) in the tree
481 # and connect them
482 5 foreach my $n ( grep { !$rooted->has_vertex( $_ ) }
483 $graph->neighbors( $v ) ) {
484 4 $rooted->add_vertex( $n );
485 4 $rooted->add_edge( $v, $n );
486 4 push( @children, $n );
487 }
488 }
489 4 @next = @children;
490 }
491 # Set the vertex classes
492 1 map { $rooted->set_vertex_attribute( $_, 'class', 'hypothetical' ) }
493 $self->hypotheticals;
494 1 map { $rooted->set_vertex_attribute( $_, 'class', 'extant' ) }
495 $self->witnesses;
496 1 $self->graph( $rooted );
497 1 $self->set_identifier( $ident );
498 }
499  
500  
501 1 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod undocumented
502 1 Text::Tradition::Error->throw(
503 'ident' => 'Stemma error',
504 'message' => $_[0],
505 );
506 }
507  
508  
509 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
510 5 __PACKAGE__->meta->make_immutable;
511
512 5 1;
513  
514 =head1 LICENSE
515  
516 This package is free software and is provided "as is" without express
517 or implied warranty. You can redistribute it and/or modify it under
518 the same terms as Perl itself.
519  
520 =head1 AUTHOR
521  
522 Tara L Andrews E<lt>aurum@cpan.orgE<gt>
« StemmaUtil.pm ↑ Summary Analysis/Result.pm »