From: tla Date: Thu, 27 Nov 2014 13:43:22 +0000 (+0100) Subject: enable tabular output with ASCII sigla. Needed for tla/stemmaweb#46 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=53ec2b6de2f39947b551b976569806d41ec2e8a0;p=scpubgit%2Fstemmatology.git enable tabular output with ASCII sigla. Needed for tla/stemmaweb#46 --- diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index df6551f..41cace4 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -1733,6 +1733,15 @@ my $t4 = Text::Tradition->new( input => 'Tabular', is( scalar $t4->collation->readings, $READINGS - 2, "Reparsed TSV merge collation has fewer readings" ); is( scalar $t4->collation->paths, $PATHS - 4, "Reparsed TSV merge collation has fewer paths" ); +# Test non-ASCII sigla +my $t5 = Text::Tradition->new( input => 'Tabular', + name => 'nonascii', + file => 't/data/armexample.xlsx', + excel => 'xlsx' ); +my $awittsv = $t5->collation->as_tsv({ noac => 1, ascii => 1 }); +my @awitlines = split( /\n/, $awittsv ); +like( $awitlines[0], qr/_A_5315622/, "Found ASCII sigil variant in TSV" ); + =end testing =cut @@ -1749,9 +1758,19 @@ sub _tabular { } my $csv = Text::CSV->new( $csv_options ); my @result; + # Make the header row - $csv->combine( map { $_->{'witness'} } @{$table->{'alignment'}} ); + my @witnesses = map { $_->{'witness'} } @{$table->{'alignment'}}; + if( $opts->{ascii} ) { + # TODO think of a fix for this + throw( "Cannot currently produce ASCII sigla with witness layers" ) + unless $opts->{noac}; + my @awits = map { $self->tradition->witness( $_ )->ascii_sigil } @witnesses; + @witnesses = @awits; + } + $csv->combine( @witnesses ); push( @result, $csv->string ); + # Make the rest of the rows foreach my $idx ( 0 .. $table->{'length'} - 1 ) { my @rowobjs = map { $_->{'tokens'}->[$idx] } @{$table->{'alignment'}}; diff --git a/base/t/text_tradition_collation.t b/base/t/text_tradition_collation.t index 09ab985..ff73da2 100644 --- a/base/t/text_tradition_collation.t +++ b/base/t/text_tradition_collation.t @@ -353,6 +353,15 @@ my $t4 = Text::Tradition->new( input => 'Tabular', sep_char => "\t" ); is( scalar $t4->collation->readings, $READINGS - 2, "Reparsed TSV merge collation has fewer readings" ); is( scalar $t4->collation->paths, $PATHS - 4, "Reparsed TSV merge collation has fewer paths" ); + +# Test non-ASCII sigla +my $t5 = Text::Tradition->new( input => 'Tabular', + name => 'nonascii', + file => 't/data/armexample.xlsx', + excel => 'xlsx' ); +my $awittsv = $t5->collation->as_tsv({ noac => 1, ascii => 1 }); +my @awitlines = split( /\n/, $awittsv ); +like( $awitlines[0], qr/_A_5315622/, "Found ASCII sigil variant in TSV" ); }