From: Tara L Andrews Date: Sun, 15 Apr 2012 22:02:13 +0000 (+0200) Subject: make the rest of the tests work with the new Witness X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=82fa4d574ae69634563ea89a5fd973f49b2d435c make the rest of the tests work with the new Witness --- diff --git a/Makefile.PL b/Makefile.PL index 4b45b4b..944bc0a 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -23,9 +23,11 @@ requires( 'Module::Load' ); requires( 'Moose' ); requires( 'Moose::Util::TypeConstraints' ); requires( 'StackTrace::Auto' ); -requires( 'Text::CSV_XS' ); +requires( 'Text::CSV' ); +requires( 'Text::TEI::Markup' ); requires( 'Throwable::X' ); requires( 'TryCatch' ); +requires( 'XML::Easy::Syntax' ); requires( 'XML::LibXML' ); requires( 'XML::LibXML::XPathContext' ); build_requires( 'Test::Warn' ); diff --git a/lib/Text/Tradition.pm b/lib/Text/Tradition.pm index fed22a3..668383f 100644 --- a/lib/Text/Tradition.pm +++ b/lib/Text/Tradition.pm @@ -101,7 +101,14 @@ Text::Tradition - a software model for a set of collated texts my @text_wits = $t->witnesses(); my $manuscript_a = $t->witness( 'A' ); - my $new_ms = $t->add_witness( 'sigil' => 'B' ); + + $t = Text::Tradition->new(); + $t->add_witness( 'sourcetype' => 'xmldesc', + 'file' => '/path/to/teitranscription.xml' ); + $t->add_witness( 'sourcetype => 'plaintext', 'sigil' => 'Q', + 'string' => 'The quick brown fox jumped over the lazy dogs' ); + ## TODO + $t->collate_texts; my $text_path_svg = $t->collation->as_svg(); ## See Text::Tradition::Collation for more on text collation itself @@ -226,7 +233,7 @@ if( $wit_a ) { is( $s->witness('X'), undef, "There is no witness X" ); ok( !exists $s->{'witnesses'}->{'X'}, "Witness key X not created" ); -my $wit_d = $s->add_witness( 'sigil' => 'D' ); +my $wit_d = $s->add_witness( 'sigil' => 'D', 'sourcetype' => 'collation' ); is( ref( $wit_d ), 'Text::Tradition::Witness', "new witness created" ); is( $wit_d->sigil, 'D', "witness has correct sigil" ); is( scalar $s->witnesses, 4, "object now has four witnesses" ); diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 721b385..ac750ea 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -5,7 +5,7 @@ use File::Temp; use File::Which; use Graph; use IPC::Run qw( run binary ); -use Text::CSV_XS; +use Text::CSV; use Text::Tradition::Collation::Reading; use Text::Tradition::Collation::RelationshipStore; use Text::Tradition::Error; @@ -1079,7 +1079,7 @@ row per witness (or witness uncorrected.) sub as_csv { my( $self ) = @_; my $table = $self->alignment_table; - my $csv = Text::CSV_XS->new( { binary => 1, quote_null => 0 } ); + my $csv = Text::CSV->new( { binary => 1, quote_null => 0 } ); my @result; # Make the header row $csv->combine( map { $_->{'witness'} } @{$table->{'alignment'}} ); diff --git a/lib/Text/Tradition/Parser/BaseText.pm b/lib/Text/Tradition/Parser/BaseText.pm index 7513135..76e4f36 100644 --- a/lib/Text/Tradition/Parser/BaseText.pm +++ b/lib/Text/Tradition/Parser/BaseText.pm @@ -249,7 +249,8 @@ sub merge_base { # Now make the witness objects, and create their text sequences foreach my $w ( grep { $_ !~ /_post$/ } keys %$edits_required ) { print STDERR "Creating witness $w\n"; - my $witness_obj = $collation->tradition->add_witness( sigil => $w ); + my $witness_obj = $collation->tradition->add_witness( + sigil => $w, sourcetype => 'collation' ); my $debug; # = $w eq 'Vb11'; my @ante_corr_seq = apply_edits( $collation, $edits_required->{$w}, $debug ); my @post_corr_seq = apply_edits( $collation, $edits_required->{$w."_post"}, $debug ) diff --git a/lib/Text/Tradition/Parser/CTE.pm b/lib/Text/Tradition/Parser/CTE.pm index e706906..fe6ed69 100644 --- a/lib/Text/Tradition/Parser/CTE.pm +++ b/lib/Text/Tradition/Parser/CTE.pm @@ -60,7 +60,7 @@ sub parse { my $id= $wit_el->getAttribute( 'xml:id' ); my @sig_parts = $xpc->findnodes( './abbr/descendant::text()', $wit_el ); my $sig = _stringify_sigil( @sig_parts ); - $tradition->add_witness( sigil => $sig, source => $wit_el->toString() ); + $tradition->add_witness( sigil => $sig, sourcetype => 'collation' ); $sigil_for{'#'.$id} = $sig; # Make life easy by keying on the ID ref syntax } diff --git a/lib/Text/Tradition/Parser/CollateText.pm b/lib/Text/Tradition/Parser/CollateText.pm index 21e54bd..8413939 100644 --- a/lib/Text/Tradition/Parser/CollateText.pm +++ b/lib/Text/Tradition/Parser/CollateText.pm @@ -39,7 +39,7 @@ sub parse { # Note the sigla. foreach my $sigil ( @{$opts->{'sigla'}} ) { $ALL_SIGLA{$sigil} = 1; - $tradition->add_witness( 'sigil' => $sigil ); + $tradition->add_witness( sigil => $sigil, sourcetype => 'collation' ); } # Now merge on the apparatus entries. merge_stone_apparatus( $tradition->collation, $lineref_hash, $opts->{'file'} ); diff --git a/lib/Text/Tradition/Parser/JSON.pm b/lib/Text/Tradition/Parser/JSON.pm index 1d7b286..1d618dc 100644 --- a/lib/Text/Tradition/Parser/JSON.pm +++ b/lib/Text/Tradition/Parser/JSON.pm @@ -108,7 +108,8 @@ sub parse { my @witnesses; # Keep the ordered list of our witnesses my %ac_wits; # Track these for later removal foreach my $sigil ( map { $_->{'witness'} } @{$table->{'alignment'}} ) { - my $wit = $tradition->add_witness( 'sigil' => $sigil ); + my $wit = $tradition->add_witness( + 'sigil' => $sigil, 'sourcetype' => 'collation' ); $wit->path( [ $c->start ] ); push( @witnesses, $wit ); my $aclabel = $c->ac_label; diff --git a/lib/Text/Tradition/Parser/Self.pm b/lib/Text/Tradition/Parser/Self.pm index 5499fc7..b8f12dd 100644 --- a/lib/Text/Tradition/Parser/Self.pm +++ b/lib/Text/Tradition/Parser/Self.pm @@ -192,7 +192,8 @@ sub parse { # Add the witness if we don't have it already. unless( $witnesses{$e->{'witness'}} ) { - $tradition->add_witness( sigil => $e->{'witness'} ); + $tradition->add_witness( + sigil => $e->{'witness'}, 'sourcetype' => 'collation' ); $witnesses{$e->{'witness'}} = 1; } $tradition->witness( $e->{'witness'} )->is_layered( 1 ) if $e->{'extra'}; diff --git a/lib/Text/Tradition/Parser/TEI.pm b/lib/Text/Tradition/Parser/TEI.pm index 7014e65..78ae542 100644 --- a/lib/Text/Tradition/Parser/TEI.pm +++ b/lib/Text/Tradition/Parser/TEI.pm @@ -124,7 +124,7 @@ sub parse { foreach my $wit_el ( $xpc->findnodes( "//$LISTWIT/$WITNESS" ) ) { my $sig = $wit_el->getAttribute( 'xml:id' ); my $source = $wit_el->toString(); - $tradition->add_witness( sigil => $sig, source => $source ); + $tradition->add_witness( sigil => $sig, sourcetype => 'collation' ); } map { $text->{$_->sigil} = [] } $tradition->witnesses; diff --git a/lib/Text/Tradition/Parser/Tabular.pm b/lib/Text/Tradition/Parser/Tabular.pm index 87fca3f..8783ff1 100644 --- a/lib/Text/Tradition/Parser/Tabular.pm +++ b/lib/Text/Tradition/Parser/Tabular.pm @@ -2,7 +2,7 @@ package Text::Tradition::Parser::Tabular; use strict; use warnings; -use Text::CSV_XS; +use Text::CSV; =head1 NAME @@ -122,7 +122,7 @@ sub parse { $csv_options->{'quote_char'} = undef; $csv_options->{'escape_char'} = undef; } - my $csv = Text::CSV_XS->new( $csv_options ); + my $csv = Text::CSV->new( $csv_options ); my $alignment_table; if( exists $opts->{'string' } ) { @@ -151,14 +151,18 @@ sub parse { # Set up the witnesses we find in the first line my @witnesses; my %ac_wits; # Track layered witness -> main witness mapping + my $aclabel = $c->ac_label; foreach my $sigil ( @{$alignment_table->[0]} ) { - my $wit = $tradition->add_witness( 'sigil' => $sigil ); - $wit->path( [ $c->start ] ); - push( @witnesses, $wit ); - my $aclabel = $c->ac_label; if( $sigil =~ /^(.*)\Q$aclabel\E$/ ) { + # Sanitize the sigil name to an XML name + $sigil = $1 . '_layered'; $ac_wits{$sigil} = $1; } + my $wit = $tradition->add_witness( + 'sigil' => $sigil, 'sourcetype' => 'collation' ); + $wit->path( [ $c->start ] ); + push( @witnesses, $wit ); + my $aclabel = $c->ac_label; } # Save the original witness text sequences. Have to loop back through diff --git a/t/text_tradition.t b/t/text_tradition.t index 6e47f40..2c7be1b 100644 --- a/t/text_tradition.t +++ b/t/text_tradition.t @@ -33,7 +33,7 @@ if( $wit_a ) { is( $s->witness('X'), undef, "There is no witness X" ); ok( !exists $s->{'witnesses'}->{'X'}, "Witness key X not created" ); -my $wit_d = $s->add_witness( 'sigil' => 'D' ); +my $wit_d = $s->add_witness( 'sigil' => 'D', 'sourcetype' => 'collation' ); is( ref( $wit_d ), 'Text::Tradition::Witness', "new witness created" ); is( $wit_d->sigil, 'D', "witness has correct sigil" ); is( scalar $s->witnesses, 4, "object now has four witnesses" );