From: tla Date: Fri, 25 Oct 2013 13:32:27 +0000 (+0200) Subject: Add as_tsv routine for tab-sep export of collation. Fixes #7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce5966fbabcce33cb17893109f1f4c0bb6aed4bd;p=scpubgit%2Fstemmatology.git Add as_tsv routine for tab-sep export of collation. Fixes #7 --- diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index ae36da5..04f3479 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -1389,12 +1389,17 @@ sub _add_graphml_data { Returns a CSV alignment table representation of the collation graph, one row per witness (or witness uncorrected.) +=head2 as_tsv + +Returns a tab-separated alignment table representation of the collation graph, +one row per witness (or witness uncorrected.) + =cut -sub as_csv { - my( $self ) = @_; +sub _tabular { + my( $self, $fieldsep ) = @_; my $table = $self->alignment_table; - my $csv = Text::CSV->new( { binary => 1, quote_null => 0 } ); + my $csv = Text::CSV->new( { binary => 1, quote_null => 0, sep_char => $fieldsep } ); my @result; # Make the header row $csv->combine( map { $_->{'witness'} } @{$table->{'alignment'}} ); @@ -1409,6 +1414,16 @@ sub as_csv { return join( "\n", @result ); } +sub as_csv { + my $self = shift; + return $self->_tabular( ',' ); +} + +sub as_tsv { + my $self = shift; + return $self->_tabular( "\t" ); +} + =head2 alignment_table Return a reference to an alignment table, in a slightly enhanced CollateX diff --git a/base/script/make_tradition.pl b/base/script/make_tradition.pl index cea10f9..bca27bd 100755 --- a/base/script/make_tradition.pl +++ b/base/script/make_tradition.pl @@ -42,8 +42,8 @@ if( $help ) { help(); } -unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)|xlsx?|db$/i ) { - help( "Input format must be one of CollateX, CSV, CTE, Self, TEI" ); +unless( $informat =~ /^(CTE|KUL|Self|TEI|CollateX|tab(ular)?)|xlsx?|db$/i ) { + help( "Input format must be one of CollateX, CTE, Self, TEI, Tabular, XLS(X), or DB" ); } my $excel = $informat =~ /^xls/i ? lc( $informat ) : undef; $informat = 'CollateX' if $informat =~ /^c(ollate)?x$/i; @@ -55,8 +55,8 @@ $informat = 'Tabular' if $informat =~ /^tab$/i; $informat = 'CollateText' if $informat =~ /^stone$/i; $informat = 'Tabular' if $informat =~ /^xls/i; -unless( $outformat =~ /^(graphml|svg|dot|stemma|csv|db)$/ ) { - help( "Output format must be one of db, graphml, svg, csv, stemma, or dot" ); +unless( $outformat =~ /^(graphml|svg|dot|stemma|(c|t)sv|db)$/ ) { + help( "Output format must be one of db, graphml, svg, csv, tsv, stemma, or dot" ); } if( $from || $to ) {