is => 'ro',
isa => 'Graph',
default => sub { Graph->new() },
+ writer => '_reset_equivalence',
);
has '_node_equivalences' => (
equivalence => 'get',
set_equivalence => 'set',
remove_equivalence => 'delete',
+ _clear_equivalence => 'clear',
},
);
eqreadings => 'get',
set_eqreadings => 'set',
remove_eqreadings => 'delete',
+ _clear_eqreadings => 'clear',
},
);
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 );
}
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();
+ # 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 ) {
+ 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 ) {
+ $self->add_equivalence_edge( @$e );
+ }
+
+ # 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;
+ $self->_make_equivalence( @$rel );
+ }
+}
+
### Output logic
sub _as_graphml {