X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=script%2Fmake_tradition.pl;h=591e56e4891d7dc40fefbea6db6403e5d6bdd814;hb=28333e88b0c5a5d267fe3086da25882cc04f1013;hp=d1af8bf6f1bfab3fd218be628e870f68de2bdeb5;hpb=56c56f0d2f97beec88fe0ee21c004336dfa45a9f;p=scpubgit%2Fstemmatology.git diff --git a/script/make_tradition.pl b/script/make_tradition.pl index d1af8bf..591e56e 100755 --- a/script/make_tradition.pl +++ b/script/make_tradition.pl @@ -14,9 +14,9 @@ binmode STDOUT, ":utf8"; eval { no warnings; binmode $DB::OUT, ":utf8"; }; my( $informat, $inbase, $outformat, $help, $language, $name, $sep, $stemmafile, - $dsn, $dbuser, $dbpass ) + $dsn, $dbuser, $dbpass, $from, $to, $dbid ) = ( '', '', '', '', 'Default', 'Tradition', "\t", '', - "dbi:SQLite:dbname=stemmaweb/db/traditions.db", undef, undef ); + "dbi:SQLite:dbname=stemmaweb/db/traditions.db", undef, undef, undef, undef, undef ); GetOptions( 'i|in=s' => \$informat, 'b|base=s' => \$inbase, @@ -27,8 +27,11 @@ GetOptions( 'i|in=s' => \$informat, 's|stemma=s' => \$stemmafile, 'u|user=s' => \$dbuser, 'p|pass=s' => \$dbpass, + 'f|from=s' => \$from, + 't|to=s' => \$to, 'sep=s' => \$sep, 'dsn=s' => \$dsn, + 'dbid=s' => \$dbid, ); if( $help ) { @@ -50,6 +53,11 @@ unless( $outformat =~ /^(graphml|svg|dot|stemma|csv|db)$/ ) { help( "Output format must be one of db, graphml, svg, csv, stemma, or dot" ); } +if( $from || $to ) { + help( "Subgraphs only supported in GraphML format" ) + unless $outformat eq 'graphml'; +} + # Do we have a base if we need it? if( $informat =~ /^(KUL|CollateText)$/ && !$inbase ) { help( "$informat input needs a base text" ); @@ -91,11 +99,19 @@ if( $outformat eq 'stemma' ) { my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn, 'extra_args' => $extra_args ); my $scope = $dir->new_scope; - my $uuid = $dir->store( $tradition ); + my $uuid; + if( $dbid ) { + $uuid = $dir->store( $dbid => $tradition ); + } else { + $uuid = $dir->store( $tradition ); + } print STDERR "Saved tradition to database with ID $uuid\n"; } else { my $output = "as_$outformat"; - print $tradition->collation->$output(); + my $opts = {}; + $opts->{'from'} = $from if $from; + $opts->{'to'} = $to if $to; + print $tradition->collation->$output( $opts ); } sub help {