Start to switch to Moose
tla [Thu, 12 May 2011 14:06:39 +0000 (16:06 +0200)]
Makefile.PL [new file with mode: 0644]
lib/Text/Tradition.pm [new file with mode: 0644]
lib/Text/Tradition/Collation.pm [new file with mode: 0644]
lib/Text/Tradition/Witness.pm [new file with mode: 0644]
script/make_svg.pl [new file with mode: 0644]
script/svg_from_csv.pl [new file with mode: 0644]

diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..701f043
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+
+use 5.010;
+use inc::Module::Install;
+author( 'Tara L Andrews <aurum@cpan.org>' );
+license( 'perl' );
+all_from( 'lib/Text/Tradition' );
+requires( 'perl' => '5.010' );
+requires( 'XML::LibXML' );
+requires( 'Graph::Easy' );
+requires( 'Text::CSV::Simple' );
+&WriteAll;
diff --git a/lib/Text/Tradition.pm b/lib/Text/Tradition.pm
new file mode 100644 (file)
index 0000000..5f8d080
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+package Text::Tradition;
+
+use Moose;
+
+has 'collation' => (
+                   is => 'ro',
+                   isa => 'Text::Tradition::Collation',
+                   init_arg => undef,
+                   );
+
+has 'witnesses' => (
+                   traits => ['Array'],
+                   is => 'rw',
+                   isa => 'ArrayRef[Text::Tradition::Witness]',
+                   handles => {
+                       all_options    => 'elements',
+                       add_option     => 'push',
+                       map_options    => 'map',
+                       option_count   => 'count',
+                       sorted_options => 'sort',
+                   },
+                   );
+
+# The user will usually be instantiating a Tradition object, and
+# examining its collation.  The information about the tradition can
+# come via several routes:
+# - graphML from CollateX or elsewhere, standalone
+# - TEI parallel segmentation
+# - Leuven-style spreadsheet of variants, converted to CSV, plus base text
+# - apparatus pulled from CTE, plus base text
+# From this we should be able to get basic witness information.
+# 
+# Alternatively the user can just give us the uncollated texts.  Then
+# instead of passing a collation, s/he is passing a set of witnesses
+# from which we will generate a collation.  Those witnesses can be in
+# plaintext or in TEI with certain constraints adopted.
+
+# So the constructor for a tradition needs to take one of these infosets,
+# and construct the collation and the witness objects.
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm
new file mode 100644 (file)
index 0000000..4bb96ca
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env perl
+
+package Text::Tradition::Collation;
+use Moose;
+
+has 'graph' => (
+               is => 'ro',
+               isa => 'Text::Tradition::Graph',
+               );
+
+# The graph is full of nodes, which have positions and equivalences.
+# These have to be stored externally to the graph itself.
+has 'positions' => (
+                   is => 'ro';
+                   isa => 'Text::Tradition::Graph::Position',
+                   );
+
+has 'equivalences' => (
+                      is => 'rw';
+                      isa => 'Text::Tradition::Graph::Equivalence',
+                      );
+
+# We need a way to access the parent object.
+has 'tradition' => (
+                   is => 'ro',
+                   isa => 'Text::Tradition',
+                   );
+
+# The collation can be created two ways:
+# 1. Collate a set of witnesses (with CollateX I guess) and process
+#    the results as in 2.
+# 2. Read a pre-prepared collation in one of a variety of formats,
+#    and make the graph from that.
+
+# The graph itself will (for now) be immutable, and the positions
+# within the graph will also be immutable.  We need to calculate those
+# positions upon graph construction.  The equivalences between graph
+# nodes will be mutable, entirely determined by the user (or possibly
+# by some semantic pre-processing provided by the user.)  So the
+# constructor should just make an empty equivalences object.  The
+# constructor will also need to make the witness objects, if we didn't
+# come through option 1.
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
diff --git a/lib/Text/Tradition/Witness.pm b/lib/Text/Tradition/Witness.pm
new file mode 100644 (file)
index 0000000..a647bc3
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+
+package Text::Tradition::Witness;
+use Moose;
+
+has 'sigil' => (
+               is => 'rw',
+               isa => 'Str',
+               );
+
+has 'text' => (
+              is => 'rw',
+              isa => 'Array',
+              );
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
diff --git a/script/make_svg.pl b/script/make_svg.pl
new file mode 100644 (file)
index 0000000..334c075
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use lib 'lib';
+use strict;
+use warnings;
+use Text::Tradition::Graph;
+
+# 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 $collation_graph = Text::Tradition::Graph->new(
+    'GraphML' => $graphml_str,
+    );
+
+print $collation_graph->as_svg();
+print STDERR "DONE\n";
diff --git a/script/svg_from_csv.pl b/script/svg_from_csv.pl
new file mode 100644 (file)
index 0000000..c469bbe
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use lib 'lib';
+use strict;
+use warnings;
+use Text::Tradition::Graph;
+
+my $collation_graph = Text::Tradition::Graph->new( 
+                                                  'CSV' => $ARGV[0],
+                                                  'base' => $ARGV[1],
+                                                  );
+
+print $collation_graph->as_svg();
+print STDERR "Done\n";