X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FParser%2FTabular.pm;h=b8e3439676abb153b48584b6f5ebdf95bc4bc53d;hb=2889d3960e1e2297137621a49143bd153cec0ea2;hp=87fca3f01c2832e7975bfaf236ef4499ac127b51;hpb=bf6e338dd676742fbd0c6d88c98795adae40429f;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Parser/Tabular.pm b/lib/Text/Tradition/Parser/Tabular.pm index 87fca3f..b8e3439 100644 --- a/lib/Text/Tradition/Parser/Tabular.pm +++ b/lib/Text/Tradition/Parser/Tabular.pm @@ -2,7 +2,7 @@ package Text::Tradition::Parser::Tabular; use strict; use warnings; -use Text::CSV_XS; +use Text::CSV; =head1 NAME @@ -108,6 +108,9 @@ foreach my $k ( keys %seen_wits ) { } } +# Check that we only have collation relationships where we need them +is( scalar $t->collation->relationships, 3, "Redundant collations were removed" ); + =end testing =cut @@ -122,7 +125,7 @@ sub parse { $csv_options->{'quote_char'} = undef; $csv_options->{'escape_char'} = undef; } - my $csv = Text::CSV_XS->new( $csv_options ); + my $csv = Text::CSV->new( $csv_options ); my $alignment_table; if( exists $opts->{'string' } ) { @@ -151,14 +154,18 @@ sub parse { # Set up the witnesses we find in the first line my @witnesses; my %ac_wits; # Track layered witness -> main witness mapping + my $aclabel = $c->ac_label; foreach my $sigil ( @{$alignment_table->[0]} ) { - my $wit = $tradition->add_witness( 'sigil' => $sigil ); - $wit->path( [ $c->start ] ); - push( @witnesses, $wit ); - my $aclabel = $c->ac_label; if( $sigil =~ /^(.*)\Q$aclabel\E$/ ) { + # Sanitize the sigil name to an XML name + $sigil = $1 . '_layered'; $ac_wits{$sigil} = $1; } + my $wit = $tradition->add_witness( + 'sigil' => $sigil, 'sourcetype' => 'collation' ); + $wit->path( [ $c->start ] ); + push( @witnesses, $wit ); + my $aclabel = $c->ac_label; } # Save the original witness text sequences. Have to loop back through @@ -244,6 +251,8 @@ sub parse { # Note that our ranks and common readings are set. $c->_graphcalc_done(1); + # Remove redundant collation relationships. + $c->relations->filter_collations(); } sub _make_nodes { @@ -277,6 +286,7 @@ sub _make_nodes { my $r = shift @rankrdgs; next if $r->is_meta; foreach my $nr ( @rankrdgs ) { + next if $nr->is_meta; if( $collation_rel ) { $collation->add_relationship( $r, $nr, $collation_rel ); } else {