From: Tara L Andrews Date: Wed, 31 Aug 2011 23:01:50 +0000 (+0200) Subject: get rid of common reading calculation for positional fun X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7e450e44cb188a835f5ca2b9f007b9782fcc753c;p=scpubgit%2Fstemmatology.git get rid of common reading calculation for positional fun --- diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 8e42931..e78fe3c 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -799,9 +799,10 @@ sub _is_within { # Walk the paths for each witness in the graph, and return the nodes # that the graph has in common. If $using_base is true, some # different logic is needed. +# NOTE This does not create paths; it merely finds common readings. sub walk_witness_paths { - my( $self, $end ) = @_; + my( $self ) = @_; # For each witness, walk the path through the graph. # Then we need to find the common nodes. # TODO This method is going to fall down if we have a very gappy @@ -810,7 +811,7 @@ sub walk_witness_paths { my @common_readings; foreach my $wit ( $self->tradition->witnesses ) { my $curr_reading = $self->start; - my @wit_path = $self->reading_sequence( $self->start, $end, + my @wit_path = $self->reading_sequence( $self->start, $self->end, $wit->sigil ); $wit->path( \@wit_path ); @@ -856,22 +857,15 @@ sub _remove_common { } -# An alternative to walk_witness_paths, for use when a collation is -# constructed from a base text and an apparatus. We have the -# sequences of readings and just need to add path edges. +# For use when a collation is constructed from a base text and an apparatus. +# We have the sequences of readings and just need to add path edges. sub make_witness_paths { my( $self ) = @_; - - my @common_readings; foreach my $wit ( $self->tradition->witnesses ) { print STDERR "Making path for " . $wit->sigil . "\n"; $self->make_witness_path( $wit ); - @common_readings = _find_common( \@common_readings, $wit->path ); - @common_readings = _find_common( \@common_readings, $wit->uncorrected_path ); } - map { $_->make_common } @common_readings; - return @common_readings; } sub make_witness_path { @@ -890,12 +884,6 @@ sub make_witness_path { } } -sub common_readings { - my $self = shift; - my @common = grep { $_->is_common } $self->readings(); - return sort { $a->position->cmp_with( $b->position ) } @common; -} - sub calculate_ranks { my $self = shift; # Walk a version of the graph where every node linked by a relationship @@ -1011,6 +999,12 @@ sub init_lemmata { $self->lemmata->{$cr->position->maxref} = $cr->name; } } + +sub common_readings { + my $self = shift; + my @common = grep { $_->is_common } $self->readings(); + return sort { $a->position->cmp_with( $b->position ) } @common; +} =item B diff --git a/lib/Text/Tradition/Parser/BaseText.pm b/lib/Text/Tradition/Parser/BaseText.pm index a8ea38f..ed2a447 100644 --- a/lib/Text/Tradition/Parser/BaseText.pm +++ b/lib/Text/Tradition/Parser/BaseText.pm @@ -343,7 +343,7 @@ sub merge_base { } # Now walk paths and calculate positional rank. - my @common_readings = $collation->make_witness_paths(); + $collation->make_witness_paths(); # Have to check relationship validity at this point, because before that # we had no paths. # foreach my $rel ( $collation->relationships ) { diff --git a/lib/Text/Tradition/Parser/CollateX.pm b/lib/Text/Tradition/Parser/CollateX.pm index 63a5635..5526d3a 100644 --- a/lib/Text/Tradition/Parser/CollateX.pm +++ b/lib/Text/Tradition/Parser/CollateX.pm @@ -120,14 +120,10 @@ sub parse { } } - # Record for each witness its sequence of readings, and determine - # the common nodes. - my @common_nodes = $collation->walk_witness_paths( $end_node ); - - # Now we have added the witnesses and their paths, so have also - # implicitly marked the common nodes. Now we can calculate their - # explicit positions. - $collation->calculate_positions( @common_nodes ); + # Now we have added the witnesses and their paths, so we can + # calculate their explicit positions. + # TODO CollateX does this, and we should just have it exported there. + $collation->calculate_positions(); } =back diff --git a/lib/Text/Tradition/Parser/TEI.pm b/lib/Text/Tradition/Parser/TEI.pm index 03b76cf..68172f7 100644 --- a/lib/Text/Tradition/Parser/TEI.pm +++ b/lib/Text/Tradition/Parser/TEI.pm @@ -30,7 +30,6 @@ the appropriate witness objects. =cut my $text = {}; # Hash of arrays, one per eventual witness we find. -my @common_readings; my $substitutions = {}; # Keep track of merged readings my $app_anchors = {}; # Track apparatus references my $app_ac = {}; # Save a.c. readings @@ -135,7 +134,7 @@ sub parse { foreach ( keys %$substitutions ) { $tradition->collation->del_reading( $tradition->collation->reading( $_ ) ); } - $tradition->collation->calculate_positions( @common_readings ); + $tradition->collation->calculate_ranks(); } sub _clean_sequence { @@ -222,7 +221,6 @@ sub _return_rdg { my $rdg = make_reading( $tradition->collation, $w ); push( @new_readings, $rdg ); unless( $in_var ) { - push( @common_readings, $rdg ); $rdg->make_common; } foreach ( @cur_wits ) { @@ -243,7 +241,6 @@ sub _return_rdg { my $rdg = make_reading( $tradition->collation, $xn->textContent, $xml_id ); push( @new_readings, $rdg ); unless( $in_var ) { - push( @common_readings, $rdg ); $rdg->make_common; } foreach( @cur_wits ) {