From: tla Date: Wed, 2 May 2012 22:32:03 +0000 (+0200) Subject: working version of rebuild_equivalence X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=04482188230a9be8e9a1335dbfcd8e3160a5768d working version of rebuild_equivalence --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index 8ed2517..8517ac1 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -107,6 +107,7 @@ has '_node_equivalences' => ( equivalence => 'get', set_equivalence => 'set', remove_equivalence => 'delete', + _clear_equivalence => 'clear', }, ); @@ -117,6 +118,7 @@ has '_equivalence_readings' => ( eqreadings => 'get', set_eqreadings => 'set', remove_eqreadings => 'delete', + _clear_eqreadings => 'clear', }, ); @@ -782,8 +784,6 @@ sub add_equivalence_edge { my( $self, $source, $target ) = @_; my $seq = $self->equivalence( $source ); my $teq = $self->equivalence( $target ); - print STDERR "Adding equivalence edge $seq -> $teq for $source -> $target\n" - if grep { $_ eq '451,2' } @_; $self->equivalence_graph->add_edge( $seq, $teq ); } @@ -1013,17 +1013,27 @@ adds all readings and edges, then makes an equivalence for all relationships. sub rebuild_equivalence { my $self = shift; my $newgraph = Graph->new(); + # Set this as the new equivalence graph + $self->_reset_equivalence( $newgraph ); + # Clear out the data hashes + $self->_clear_equivalence; + $self->_clear_eqreadings; + + # Add the readings foreach my $r ( $self->collation->readings ) { - $newgraph->add_vertex( $r->id ); + my $rid = $r->id; + $newgraph->add_vertex( $rid ); + $self->set_equivalence( $rid, $rid ); + $self->set_eqreadings( $rid, [ $rid ] ); } + + # Now add the edges foreach my $e ( $self->collation->paths ) { - $newgraph->add_edge( @$e ); + $self->add_equivalence_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. + + # Now equate the colocated readings. 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;