...and remove debug statement
[scpubgit/stemmatology.git] / base / script / make_tradition.pl
index f4eaf16..cea10f9 100755 (executable)
@@ -17,7 +17,8 @@ eval { no warnings; binmode $DB::OUT, ":utf8"; };
 my( $informat, $outformat, $language, $name, $sep, $dsn )  = ( '', '', 'Default', 
        'Tradition', "\t", "dbi:SQLite:dbname=db/traditions.db" );
 # Variables with no default
-my( $inbase, $help, $stemmafile,  $dbuser, $dbpass, $from, $to, $dbid, $debug, $nonlinear );
+my( $inbase, $help, $stemmafile,  $dbuser, $dbpass, $from, $to, $dbid, 
+       $nocalc, $nonlinear );
 
 GetOptions( 'i|in=s'    => \$informat,
             'b|base=s'  => \$inbase,
@@ -33,17 +34,18 @@ GetOptions( 'i|in=s'    => \$informat,
             'nl|nonlinear' => \$nonlinear,
             'sep=s'            => \$sep,
             'dsn=s'            => \$dsn,
-           'dbid=s'    => \$dbid,
-               'debug'     => \$debug
+            'dbid=s'    => \$dbid,
+            'nc|nocalc' => \$nocalc,
     );
 
 if( $help ) {
     help();
 }
 
-unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)|stone|db$/i ) {
+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" );
 }
+my $excel = $informat =~ /^xls/i ? lc( $informat ) : undef;
 $informat = 'CollateX' if $informat =~ /^c(ollate)?x$/i;
 $informat = 'KUL' if $informat =~ /^kul$/i;
 $informat = 'CTE' if $informat =~ /^cte$/i;
@@ -51,6 +53,7 @@ $informat = 'Self' if $informat =~ /^self$/i;
 $informat = 'TEI' if $informat =~ /^tei$/i;
 $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" );
@@ -86,11 +89,30 @@ if( $informat eq 'db' ) {
        $args{'base'} = $inbase if $inbase;
        $args{'language'} = $language if $language;
        $args{'name'} = $name if $name;
-       $args{'sep_char'} = $sep if $informat eq 'Tabular';
+       $args{'nocalc'} = 1 if $nocalc;
+       if( $informat eq 'Tabular' ) {
+               if( $excel ) {
+                       $args{'excel'} = $excel;
+               } else {
+                       $args{'sep_char'} = $sep;
+               }
+       }
+       # If we are writing to the database, use that DB as the userstore.
+       if( $outformat eq 'db' ) {
+               unless( $dir ) {
+                       my $extra_args = { 'create' => 1 };
+                       $extra_args->{'user'} = $dbuser if $dbuser;
+                       $extra_args->{'password'} = $dbpass if $dbpass;
+                       $dir = Text::Tradition::Directory->new( 'dsn' => $dsn,
+                               'extra_args' => $extra_args );
+               }
+               $args{'userstore'} = $dir;
+       }
        ### Custom hacking for Stone
        if( $informat eq 'CollateText' ) {
                $args{'sigla'} = [ qw/ S M X V Z Bb B K W L / ];
        }
+       my $scope = $dir->new_scope() if $dir;
        $tradition = Text::Tradition->new( %args );
 }
 if( $stemmafile ) {
@@ -100,7 +122,7 @@ if( $stemmafile ) {
 
 # Now output what we have been asked to.
 if( $outformat eq 'stemma' ) {
-    my $cdata = character_input( $tradition->collation->alignment_table );
+    my $cdata = character_input( $tradition );
     try {
        print phylip_pars( $cdata );
     } catch( Text::Tradition::Error $e ) {
@@ -127,7 +149,7 @@ if( $outformat eq 'stemma' ) {
     my $opts = {};
     $opts->{'from'} = $from if $from;
     $opts->{'to'} = $to if $to;
-    $opts->{'nocalc'} = 1 if $debug;
+    $opts->{'nocalc'} = 1 if $nocalc;
     print $tradition->collation->$output( $opts );
 }