8 use Text::Tradition::Stemma;
10 binmode STDERR, ":utf8";
11 binmode STDOUT, ":utf8";
12 eval { no warnings; binmode $DB::OUT, ":utf8"; };
14 my( $informat, $inbase, $outformat, $help, $linear, $name, $HACK )
15 = ( '', '', '', '', 1, 0 );
17 GetOptions( 'i|in=s' => \$informat,
18 'b|base=s' => \$inbase,
19 'o|out=s' => \$outformat,
20 'l|linear!' => \$linear,
30 unless( $informat =~ /^(CSV|CTE|KUL|Self|TEI|CollateX|tab(ular)?)$/i ) {
31 help( "Input format must be one of CollateX, CSV, CTE, Self, TEI" );
33 $informat = 'CollateX' if $informat =~ /^c(ollate)?x$/i;
34 $informat = 'KUL' if $informat =~ /^kul$/i;
35 $informat = 'CTE' if $informat =~ /^cte$/i;
36 $informat = 'Self' if $informat =~ /^self$/i;
37 $informat = 'TEI' if $informat =~ /^tei$/i;
38 $informat = 'Tabular' if $informat =~ /^tab$/i;
40 unless( $outformat =~ /^(graphml|svg|dot|stemma|csv)$/ ) {
41 help( "Output format must be one of graphml, svg, csv, stemma, or dot" );
44 # Do we have a base if we need it?
45 if( $informat eq 'KUL' && !$inbase ) {
46 help( "$informat input needs a base text" );
51 # First: read the base. Make a graph, but also note which
52 # nodes represent line beginnings.
53 my %args = ( 'input' => $informat,
55 'linear' => $linear );
56 $args{'base'} = $inbase if $inbase;
57 $args{'name'} = $name if $name;
58 my $tradition = Text::Tradition->new( %args );
61 # Remove witnesses C, E, G in the Matthew text
63 foreach( $tradition->collation->paths() ) {
64 $tradition->collation->del_path( $_ ) if $_->label =~ /^[ceg]$/i;
66 foreach( $tradition->collation->readings() ) {
67 if( !$_->outgoing() && !$_->incoming() ) {
68 print STDERR "Deleting reading " . $_->label . "\n";
69 $tradition->collation->del_reading( $_ );
74 # Now output what we have been asked to.
75 if( $outformat eq 'stemma' ) {
76 my $stemma = Text::Tradition::Stemma->new(
77 'collation' => $tradition->collation );
78 my( $result, $tree ) = $stemma->run_phylip_pars();
82 print STDERR "Bad result: $tree";
85 my $output = "as_$outformat";
86 print $tradition->collation->$output();
92 Usage: $0 -i [format] -o [format] (--base [filename]) (--(no)linear) [inputfile]
93 i, input: Format of the input file. Must be one of CollateX, CSV, CTE, Self, TEI.
94 o, output: Format of the output. Must be one of svg, dot, graphml, csv, stemma.
95 b, base: Filename that contains a base text. Needed for CSV input.
96 l, linear: Treat transposed readings separately, producing a linear graph.
97 If nolinear, treat transposed readings as the same node.
98 h, help: Print this message.
102 print STDERR "$msg\n";
104 exit ($msg ? 1 : 0 );