use warnings;
use Getopt::Long;
use Text::Tradition;
+use Text::Tradition::Directory;
use Text::Tradition::StemmaUtil;
binmode STDERR, ":utf8";
binmode STDOUT, ":utf8";
eval { no warnings; binmode $DB::OUT, ":utf8"; };
-my( $informat, $inbase, $outformat, $help, $linear, $name, $HACK, $sep )
- = ( '', '', '', '', 1, 'Tradition', 0, "\t" );
+my( $informat, $inbase, $outformat, $help, $language, $name, $HACK, $sep, $stemmafile,
+ $dsn, $dbuser, $dbpass )
+ = ( '', '', '', '', 1, 'Tradition', 0, "\t", '',
+ "dbi:SQLite:dbname=stemmaweb/db/traditions.db", undef, undef );
GetOptions( 'i|in=s' => \$informat,
'b|base=s' => \$inbase,
'o|out=s' => \$outformat,
- 'l|linear!' => \$linear,
- 'n|name=s' => \$name,
+ 'l|language=s' => \$language,
+ 'n|name=s' => \$name,
'h|help' => \$help,
+ 's|stemma=s' => \$stemmafile,
+ 'u|user=s' => \$dbuser,
+ 'p|pass=s' => \$dbpass,
'sep=s' => \$sep,
'hack' => \$HACK,
+ 'dsn=s' => \$dsn,
);
if( $help ) {
$informat = 'Tabular' if $informat =~ /^tab$/i;
$informat = 'CollateText' if $informat =~ /^stone$/i;
-unless( $outformat =~ /^(graphml|svg|dot|stemma|csv)$/ ) {
- help( "Output format must be one of graphml, svg, csv, stemma, or dot" );
+unless( $outformat =~ /^(graphml|svg|dot|stemma|csv|db)$/ ) {
+ help( "Output format must be one of db, graphml, svg, csv, stemma, or dot" );
}
# Do we have a base if we need it?
# First: read the base. Make a graph, but also note which
# nodes represent line beginnings.
my %args = ( 'input' => $informat,
- 'file' => $input,
- 'linear' => $linear );
+ '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
$args{'sigla'} = [ qw/ S M X V Z Bb B K W L / ];
}
my $tradition = Text::Tradition->new( %args );
+if( $stemmafile ) {
+ my $stemma = $tradition->add_stemma( dotfile => $stemmafile );
+ print STDERR "Saved stemma at $stemmafile\n" if $stemma;
+}
### Custom hacking
# Remove witnesses C, E, G in the Matthew text
if( $HACK ) {
- my @togo = qw/ C E G /;
- $tradition->collation->clear_witness( @togo );
- $tradition->del_witness( @togo );
+ # Set the funny name while we're at it
+ my $oldname = $tradition->name;
+ $oldname =~ s/(\d)/ $1/;
+ my $newname = "\x{17d}amanakagrut\x{2bf}iwn " . ucfirst( $oldname );
+ $tradition->name( $newname );
}
# Now output what we have been asked to.
} else {
print STDERR "Bad result: $tree";
}
+} 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 );
+ my $scope = $dir->new_scope;
+ my $uuid = $dir->store( $tradition );
+ print STDERR "Saved tradition to database with ID $uuid\n";
} else {
my $output = "as_$outformat";
print $tradition->collation->$output();