8 use Text::Tradition::Directory;
9 use Text::Tradition::StemmaUtil;
11 binmode STDERR, ":utf8";
12 binmode STDOUT, ":utf8";
13 eval { no warnings; binmode $DB::OUT, ":utf8"; };
15 my( $informat, $inbase, $outformat, $help, $linear, $name, $HACK, $sep, $stemmafile, $dsn )
16 = ( '', '', '', '', 1, 'Tradition', 0, "\t", '',
17 "dbi:SQLite:dbname=stemmaweb/db/traditions.db" );
19 GetOptions( 'i|in=s' => \$informat,
20 'b|base=s' => \$inbase,
21 'o|out=s' => \$outformat,
22 'l|linear!' => \$linear,
25 's|stemma=s' => \$stemmafile,
35 unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)|stone$/i ) {
36 help( "Input format must be one of CollateX, CSV, CTE, Self, TEI" );
38 $informat = 'CollateX' if $informat =~ /^c(ollate)?x$/i;
39 $informat = 'KUL' if $informat =~ /^kul$/i;
40 $informat = 'CTE' if $informat =~ /^cte$/i;
41 $informat = 'Self' if $informat =~ /^self$/i;
42 $informat = 'TEI' if $informat =~ /^tei$/i;
43 $informat = 'Tabular' if $informat =~ /^tab$/i;
44 $informat = 'CollateText' if $informat =~ /^stone$/i;
46 unless( $outformat =~ /^(graphml|svg|dot|stemma|csv|db)$/ ) {
47 help( "Output format must be one of db, graphml, svg, csv, stemma, or dot" );
50 # Do we have a base if we need it?
51 if( $informat =~ /^(KUL|CollateText)$/ && !$inbase ) {
52 help( "$informat input needs a base text" );
54 $sep = "\t" if $sep eq 'tab';
58 # First: read the base. Make a graph, but also note which
59 # nodes represent line beginnings.
60 my %args = ( 'input' => $informat,
62 'linear' => $linear );
63 $args{'base'} = $inbase if $inbase;
64 $args{'name'} = $name if $name;
65 $args{'sep_char'} = $sep if $informat eq 'Tabular';
66 ### Custom hacking for Stone
67 if( $informat eq 'CollateText' ) {
68 $args{'sigla'} = [ qw/ S M X V Z Bb B K W L / ];
70 my $tradition = Text::Tradition->new( %args );
72 my $stemma = $tradition->add_stemma( $stemmafile );
73 print STDERR "Saved stemma at $stemmafile\n" if $stemma;
77 # Remove witnesses C, E, G in the Matthew text
79 my @togo = qw/ C E G /;
80 $tradition->collation->clear_witness( @togo );
81 $tradition->del_witness( @togo );
84 # Now output what we have been asked to.
85 if( $outformat eq 'stemma' ) {
86 my $cdata = character_input( $tradition->collation->make_alignment_table );
87 my( $result, $tree ) = phylip_pars( $cdata );
91 print STDERR "Bad result: $tree";
93 } elsif( $outformat eq 'db' ) {
94 my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn,
95 'extra_args' => { 'create' => 1 } );
96 my $scope = $dir->new_scope;
97 my $uuid = $dir->store( $tradition );
98 print STDERR "Saved tradition to database with ID $uuid\n";
100 my $output = "as_$outformat";
101 print $tradition->collation->$output();
106 print STDERR << "EOF"
107 Usage: $0 -i [format] -o [format] (--base [filename]) (--(no)linear) [inputfile]
108 i, input: Format of the input file. Must be one of CollateX, CSV, CTE, Self, TEI.
109 o, output: Format of the output. Must be one of svg, dot, graphml, csv, stemma.
110 b, base: Filename that contains a base text. Needed for CSV input.
111 l, linear: Treat transposed readings separately, producing a linear graph.
112 If nolinear, treat transposed readings as the same node.
113 h, help: Print this message.
117 print STDERR "$msg\n";
119 exit ($msg ? 1 : 0 );