X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FParser%2FJSON.pm;h=1d7b2869d95c1bb712d014c5d6c2b3d88af9c679;hb=3bf5d6f1070741054a890165852039422030d963;hp=3e30651f1c3d7e2b356d9cd010ecaae57a745b9e;hpb=b0b4421ad99abdb67e413f16219e932576212e50;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Parser/JSON.pm b/lib/Text/Tradition/Parser/JSON.pm index 3e30651..1d7b286 100644 --- a/lib/Text/Tradition/Parser/JSON.pm +++ b/lib/Text/Tradition/Parser/JSON.pm @@ -182,6 +182,9 @@ sub parse { foreach my $rdg ( grep { $_->is_lacuna } $c->readings ) { $c->del_reading( $rdg ) unless $c->reading_witnesses( $rdg ); } + + # Note that our ranks and common readings are set. + $c->_graphcalc_done(1); } =head2 make_nodes( $collation, $index, @tokenlist ) @@ -195,6 +198,7 @@ sub make_nodes { 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] ); @@ -203,17 +207,30 @@ sub make_nodes { $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; }