From: Tara L Andrews Date: Wed, 2 May 2012 21:52:14 +0000 (+0200) Subject: add method for initializing/resetting equivalence graph X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e1083e99492d7847a1a5112751a1fba61d5c4655;p=scpubgit%2Fstemmatology.git add method for initializing/resetting equivalence graph --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index c7728cd..8ed2517 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -97,6 +97,7 @@ has 'equivalence_graph' => ( is => 'ro', isa => 'Graph', default => sub { Graph->new() }, + writer => '_reset_equivalence', ); has '_node_equivalences' => ( @@ -1002,6 +1003,34 @@ sub _find_equiv_without { return keys %found; } +=head2 rebuild_equivalence + +(Re)build the equivalence graph from scratch. Dumps the graph, makes a new one, +adds all readings and edges, then makes an equivalence for all relationships. + +=cut + +sub rebuild_equivalence { + my $self = shift; + my $newgraph = Graph->new(); + foreach my $r ( $self->collation->readings ) { + $newgraph->add_vertex( $r->id ); + } + foreach my $e ( $self->collation->paths ) { + $newgraph->add_edge( @$e ); + } + # Set this as the new equivalence graph + $self->_reset_equivalence( $newgraph ); + + # Now collapse some nodes. This does no testing; it assumes that all + # preexisting relationships are valid. + foreach my $rel ( $self->relationships ) { + my $relobj = $self->get_relationship( $rel ); + next unless $relobj && $relobj->colocated; + $self->_make_equivalence( @$rel ); + } +} + ### Output logic sub _as_graphml {