X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=base%2Flib%2FText%2FTradition%2FCollation.pm;h=4597da1b71c2daeb8aa03eaeb8bd1b53c319e69d;hb=16203db579ad596e24f3524b845bcca8a1d544a5;hp=04f3479c0e72a1da04ba7a42a14d67c336930f9f;hpb=f08498a5d4fa2d83a79cf138b796ae68696242dc;p=scpubgit%2Fstemmatology.git diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index 04f3479..4597da1 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -1394,12 +1394,54 @@ row per witness (or witness uncorrected.) Returns a tab-separated alignment table representation of the collation graph, one row per witness (or witness uncorrected.) +=begin testing + +use Text::Tradition; + +my $READINGS = 311; +my $PATHS = 361; + +my $datafile = 't/data/florilegium_tei_ps.xml'; +my $tradition = Text::Tradition->new( 'input' => 'TEI', + 'name' => 'test0', + 'file' => $datafile, + 'linear' => 1 ); + +my $c = $tradition->collation; +# Export the thing to CSV +my $csvstr = $c->as_csv(); +my $t2 = Text::Tradition->new( input => 'Tabular', + name => 'test2', + string => $csvstr, + sep_char => ',' ); +is( scalar $t2->collation->readings, $READINGS, "Reparsed CSV collation has all readings" ); +is( scalar $t2->collation->paths, $PATHS, "Reparsed CSV collation has all paths" ); + +# Now do it with TSV +my $tsvstr = $c->as_tsv(); +my $t3 = Text::Tradition->new( input => 'Tabular', + name => 'test3', + string => $tsvstr, + sep_char => "\t" ); +is( scalar $t3->collation->readings, $READINGS, "Reparsed TSV collation has all readings" ); +is( scalar $t3->collation->paths, $PATHS, "Reparsed TSV collation has all paths" ); + + +=end testing + =cut sub _tabular { my( $self, $fieldsep ) = @_; my $table = $self->alignment_table; - my $csv = Text::CSV->new( { binary => 1, quote_null => 0, sep_char => $fieldsep } ); + my $csv_options = { binary => 1, quote_null => 0 }; + $csv_options->{'sep_char'} = $fieldsep; + if( $fieldsep eq "\t" ) { + # If it is really tab separated, nothing is an escape char. + $csv_options->{'quote_char'} = undef; + $csv_options->{'escape_char'} = ''; + } + my $csv = Text::CSV->new( $csv_options ); my @result; # Make the header row $csv->combine( map { $_->{'witness'} } @{$table->{'alignment'}} );