# $rel->type, $rel->from->id, $rel->to->id );
# }
# }
- $collation->calculate_ranks();
+ $collation->calculate_common_readings(); # will implicitly rank
}
=item B<read_base>
}
# Rank the readings.
- $collation->calculate_ranks() if $collation->linear;
+ $collation->calculate_common_readings(); # will implicitly rank
# Save the text for each witness so that we can ensure consistency
# later on
my( $c, $idx, @tokens ) = @_;
my %unique;
my @readings;
+ my $commonctr = 0;
foreach my $j ( 0 .. $#tokens ) {
if( $tokens[$j] ) {
my $word = _restore_punct( $tokens[$j] );
$rdg = $unique{$word};
} else {
my %args = ( 'id' => join( ',', $idx, $j+1 ),
+ 'rank' => $idx,
'text' => $word,
'collation' => $c );
- $args{'is_lacuna'} = 1 if $word eq '#LACUNA#';
+ if( $word eq '#LACUNA#' ) {
+ $args{'is_lacuna'} = 1
+ } else {
+ $commonctr++;
+ }
$rdg = Text::Tradition::Collation::Reading->new( %args );
$unique{$word} = $rdg;
}
push( @readings, $rdg );
} else {
+ $commonctr++;
push( @readings, undef );
}
}
+ if( $commonctr == 1 ) {
+ # Whichever reading isn't a lacuna is a common node.
+ foreach my $rdg ( values %unique ) {
+ next if $rdg->is_lacuna;
+ $rdg->is_common( 1 );
+ }
+ }
map { $c->add_reading( $_ ) } values( %unique );
return @readings;
}
=cut
my( $IDKEY, $TOKENKEY, $TRANSPOS_KEY, $RANK_KEY,
- $START_KEY, $END_KEY, $LACUNA_KEY,
+ $START_KEY, $END_KEY, $LACUNA_KEY, $COMMON_KEY,
$SOURCE_KEY, $TARGET_KEY, $WITNESS_KEY, $EXTRA_KEY, $RELATIONSHIP_KEY,
$SCOPE_KEY, $CORRECT_KEY, $INDEP_KEY )
= qw/ id text identical rank
- is_start is_end is_lacuna
+ is_start is_end is_lacuna is_common
source target witness extra relationship
scope non_correctable non_independent /;
my $reading_options = {
'id' => $n->{$IDKEY},
'is_lacuna' => $n->{$LACUNA_KEY},
+ 'is_common' => $n->{$COMMON_KEY},
};
my $rank = $n->{$RANK_KEY};
$reading_options->{'rank'} = $rank if $rank;
# text and identical rank that can be merged.
$tradition->collation->flatten_ranks();
+ # And now that we've done that, calculate the common nodes.
+ $tradition->collation->calculate_common_readings();
+
# Save the text for each witness so that we can ensure consistency
# later on
$tradition->collation->text_from_paths();
if( $word ) {
my $reading = $nodes->{$word};
my $wit = $witnesses[$w];
- $DB::single = 1 unless $wit;
push( @{$wit->path}, $reading );
} # else skip it for empty readings.
}
sub make_nodes {
my( $collation, $row, $index ) = @_;
my %unique;
+ my $commonctr = 0; # Holds the number of unique readings + gaps, ex. lacunae.
foreach my $w ( @$row ) {
$unique{$w} = 1 if $w;
+ $commonctr +=1 unless ( $w && $w eq '#LACUNA#' );
}
my $ctr = 1;
foreach my $w ( keys %unique ) {
'rank' => $index,
'text' => $w,
};
- $rargs->{'is_lacuna'} = 1 if $w eq '#LACUNA#';
+ if( $w eq '#LACUNA#' ) {
+ $rargs->{'is_lacuna'} = 1;
+ } elsif( $commonctr == 1 ) {
+ $rargs->{'is_common'} = 1;
+ }
my $r = $collation->add_reading( $rargs );
$unique{$w} = $r;
$ctr++;