move scripts where they belong
Tara L Andrews [Tue, 24 May 2011 13:48:33 +0000 (15:48 +0200)]
script/svg_from_csv.pl
script/svg_from_graphml.pl [new file with mode: 0644]

index 40fa7f5..7a154c4 100644 (file)
@@ -1,14 +1,42 @@
-#!/usr/bin/env perl
+#!/usr/bin/perl
 
 use lib 'lib';
 use strict;
 use warnings;
 use Text::Tradition;
 
-my $collation_graph = Text::Tradition->new( 
-                                                  'CSV' => $ARGV[0],
-                                                  'base' => $ARGV[1],
-                                                  );
+# First: read the base. Make a graph, but also note which
+# nodes represent line beginnings.
+
+my $tradition = Text::Tradition->new(
+    'CSV' => $ARGV[0],
+    'base' => $ARGV[1],
+    );
+
+
+print $tradition->collation->as_svg();
+print STDERR "DONE\n";
+__END__
+my $rows = 0;
+my $matrix = [];
+foreach my $pos ( $collation_graph->{'positions'}->all ) {
+    my @p_nodes = $collation_graph->{'positions'}->nodes_at_position( $pos );
+    $rows = scalar @p_nodes
+       if $rows < scalar @p_nodes;
+    push( @$matrix, \@p_nodes );
+}
+print "<html><head><title>A table</title></head><body><table>\n";
+foreach my $i ( 0 .. $rows-1 ) {
+    print "\t<tr>\n";
+    foreach my $col( @$matrix ) {
+       my $str = '';
+       if( $col->[$i] ) {
+           $str = $collation_graph->node( $col->[$i] )->label;
+       }
+       printf( "\t\t<td>%s</td>\n", $str );
+    }
+    print "\t</tr>\n";
+}
+print "</table></body></html>\n";
+    
 
-print $collation_graph->as_svg();
-print STDERR "Done\n";
diff --git a/script/svg_from_graphml.pl b/script/svg_from_graphml.pl
new file mode 100644 (file)
index 0000000..a98cde4
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use lib 'lib';
+use strict;
+use warnings;
+use Text::Tradition;
+
+# First: read the base. Make a graph, but also note which
+# nodes represent line beginnings.
+
+open( GRAPH, $ARGV[0] ) or die "Could not read file $ARGV[0]";
+my @lines = <GRAPH>;
+close GRAPH;
+my $graphml_str = join( '', @lines );
+
+my $tradition = Text::Tradition->new(
+    'GraphML' => $graphml_str,
+    );
+
+print $tradition->collation->as_svg();
+print STDERR "DONE\n";