X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=script%2Fmake_tradition.pl;h=16d85199ebc0dfa345bb4d9a21783818c1994c08;hb=96ba0418c65f3450b419aea78db41bf697612b63;hp=50aab73e4a6784ae0ad3bf95b98a543807a17c8a;hpb=10943ab0b79fbd489f6beb3b81a13ed8cbcfafcf;p=scpubgit%2Fstemmatology.git diff --git a/script/make_tradition.pl b/script/make_tradition.pl index 50aab73..16d8519 100755 --- a/script/make_tradition.pl +++ b/script/make_tradition.pl @@ -17,7 +17,7 @@ eval { no warnings; binmode $DB::OUT, ":utf8"; }; my( $informat, $outformat, $language, $name, $sep, $dsn ) = ( '', '', 'Default', 'Tradition', "\t", "dbi:SQLite:dbname=stemmaweb/db/traditions.db" ); # Variables with no default -my( $inbase, $help, $stemmafile, $dbuser, $dbpass, $from, $to, $dbid, $debug ); +my( $inbase, $help, $stemmafile, $dbuser, $dbpass, $from, $to, $dbid, $debug, $nonlinear ); GetOptions( 'i|in=s' => \$informat, 'b|base=s' => \$inbase, @@ -30,6 +30,7 @@ GetOptions( 'i|in=s' => \$informat, 'p|pass=s' => \$dbpass, 'f|from=s' => \$from, 't|to=s' => \$to, + 'nl|nonlinear' => \$nonlinear, 'sep=s' => \$sep, 'dsn=s' => \$dsn, 'dbid=s' => \$dbid, @@ -40,7 +41,7 @@ if( $help ) { help(); } -unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)|stone$/i ) { +unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)|stone|db$/i ) { help( "Input format must be one of CollateX, CSV, CTE, Self, TEI" ); } $informat = 'CollateX' if $informat =~ /^c(ollate)?x$/i; @@ -56,8 +57,8 @@ unless( $outformat =~ /^(graphml|svg|dot|stemma|csv|db)$/ ) { } if( $from || $to ) { - help( "Subgraphs only supported in GraphML format" ) - unless $outformat eq 'graphml'; + help( "Subgraphs only supported in GraphML, dot, or SVG format" ) + unless $outformat =~ /^(graphml|dot|svg)$/; } # Do we have a base if we need it? @@ -67,20 +68,31 @@ if( $informat =~ /^(KUL|CollateText)$/ && !$inbase ) { $sep = "\t" if $sep eq 'tab'; my $input = $ARGV[0]; - -# First: read the base. Make a graph, but also note which -# nodes represent line beginnings. -my %args = ( 'input' => $informat, - 'file' => $input ); -$args{'base'} = $inbase if $inbase; -$args{'language'} = $language if $language; -$args{'name'} = $name if $name; -$args{'sep_char'} = $sep if $informat eq 'Tabular'; -### Custom hacking for Stone -if( $informat eq 'CollateText' ) { - $args{'sigla'} = [ qw/ S M X V Z Bb B K W L / ]; +my $tradition; +my $dir; +if( $informat eq 'db' ) { + my $dbargs = { dsn => $dsn }; + $dbargs->{'extra_args'}->{'user'} = $dbuser if $dbuser; + $dbargs->{'extra_args'}->{'password'} = $dbpass if $dbpass; + $dir = Text::Tradition::Directory->new( $dbargs ); + my $scope = $dir->new_scope(); + $tradition = $dir->lookup( $input ); +} else { + # First: read the base. Make a graph, but also note which + # nodes represent line beginnings. + my %args = ( 'input' => $informat, + 'file' => $input ); + $args{'linear'} = 0 if $nonlinear; + $args{'base'} = $inbase if $inbase; + $args{'language'} = $language if $language; + $args{'name'} = $name if $name; + $args{'sep_char'} = $sep if $informat eq 'Tabular'; + ### Custom hacking for Stone + if( $informat eq 'CollateText' ) { + $args{'sigla'} = [ qw/ S M X V Z Bb B K W L / ]; + } + $tradition = Text::Tradition->new( %args ); } -my $tradition = Text::Tradition->new( %args ); if( $stemmafile ) { my $stemma = $tradition->add_stemma( dotfile => $stemmafile ); print STDERR "Saved stemma at $stemmafile\n" if $stemma; @@ -95,11 +107,13 @@ if( $outformat eq 'stemma' ) { print STDERR "Bad result: " . $e->message; } } elsif( $outformat eq 'db' ) { - my $extra_args = { 'create' => 1 }; - $extra_args->{'user'} = $dbuser if $dbuser; - $extra_args->{'password'} = $dbpass if $dbpass; - my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn, - 'extra_args' => $extra_args ); + 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 ); + } my $scope = $dir->new_scope; my $uuid; if( $dbid ) {