remove analysis tests from CPAN module too
[scpubgit/stemmatology.git] / lib / Text / Tradition.pm
index bbdb45b..20f33e1 100644 (file)
@@ -7,7 +7,7 @@ use Text::Tradition::Stemma;
 use Text::Tradition::Witness;
 
 use vars qw( $VERSION );
-$VERSION = "0.1";
+$VERSION = "0.3";
 
 has 'collation' => (
     is => 'ro',
@@ -34,10 +34,22 @@ has 'name' => (
     default => 'Tradition',
     );
     
-has 'stemma' => (
+has 'language' => (
        is => 'ro',
-       isa => 'Text::Tradition::Stemma',
-       writer => '_add_stemma',
+       isa => 'Str',
+       );
+    
+has 'stemmata' => (
+       traits => ['Array'],
+       isa => 'ArrayRef[Text::Tradition::Stemma]',
+       handles => {
+               stemmata => 'elements',
+               _add_stemma => 'push',
+               stemma => 'get',
+               stemma_count => 'count',
+               clear_stemmata => 'clear',
+       },
+       default => sub { [] },
        );
   
 # Create the witness before trying to add it
@@ -127,6 +139,8 @@ following:
 
 =item * CTE - a TEI XML format produced by Classical Text Editor
 
+=item * JSON - an alignment table in JSON format, as produced by CollateX and other tools
+
 =item * KUL - a specific CSV format for variants, not documented here
 
 =item * TEI - a TEI parallel segmentation format file
@@ -253,7 +267,7 @@ sub BUILD {
         $self->_save_collation( $collation );
 
         # Call the appropriate parser on the given data
-        my @format_standalone = qw/ Self CollateText CollateX CTE TEI Tabular /;
+        my @format_standalone = qw/ Self CollateText CollateX CTE JSON TEI Tabular /;
         my @format_basetext = qw/ KUL /;
         my $use_base;
         my $format = $init_args->{'input'};
@@ -298,18 +312,30 @@ my $t = Text::Tradition->new(
     'file'  => 't/data/simple.txt',
     );
 
+is( $t->stemma_count, 0, "No stemmas added yet" );
 my $s;
-ok( $s = $t->add_stemma( 't/data/simple.dot' ), "Added a simple stemma" );
+ok( $s = $t->add_stemma( dotfile => 't/data/simple.dot' ), "Added a simple stemma" );
 is( ref( $s ), 'Text::Tradition::Stemma', "Got a stemma object returned" );
-is( $t->stemma, $s, "Stemma is the right one" );
+is( $t->stemma_count, 1, "Tradition claims to have a stemma" );
+is( $t->stemma(0), $s, "Tradition hands back the right stemma" );
 
 =end testing
 
 =cut
 
 sub add_stemma {
-       my( $self, $dot ) = @_;
-       open my $stemma_fh, '<', $dot or warn "Could not open file $dot";
+       my $self = shift;
+       my %opts = @_;
+       my $stemma_fh;
+       if( $opts{'dotfile'} ) {
+               open $stemma_fh, '<', $opts{'dotfile'}
+                       or warn "Could not open file " . $opts{'dotfile'};
+       } elsif( $opts{'dot'} ) {
+               my $str = $opts{'dot'};
+               open $stemma_fh, '<', \$str;
+       }
+       # Assume utf-8
+       binmode $stemma_fh, ':utf8';
        my $stemma = Text::Tradition::Stemma->new( 
                'collation' => $self->collation,
                'dot' => $stemma_fh );