4 use Test::More 'no_plan';
13 my $cxfile = 't/data/Collatex-16.xml';
14 my $t = Text::Tradition->new(
16 'input' => 'CollateX',
19 my $c = $t->collation;
21 my $rno = scalar $c->readings;
22 # Split n21 for testing purposes
23 my $new_r = $c->add_reading( { 'id' => 'n21p0', 'text' => 'un', 'join_next' => 1 } );
24 my $old_r = $c->reading( 'n21' );
25 $old_r->alter_text( 'to' );
26 $c->del_path( 'n20', 'n21', 'A' );
27 $c->add_path( 'n20', 'n21p0', 'A' );
28 $c->add_path( 'n21p0', 'n21', 'A' );
30 ok( $c->reading( 'n21p0' ), "New reading exists" );
31 is( scalar $c->readings, $rno, "Reading add offset by flatten_ranks" );
33 # Combine n3 and n4 ( with his )
34 $c->merge_readings( 'n3', 'n4', 1 );
35 ok( !$c->reading('n4'), "Reading n4 is gone" );
36 is( $c->reading('n3')->text, 'with his', "Reading n3 has both words" );
38 # Collapse n9 and n10 ( rood / root )
39 $c->merge_readings( 'n9', 'n10' );
40 ok( !$c->reading('n10'), "Reading n10 is gone" );
41 is( $c->reading('n9')->text, 'rood', "Reading n9 has an unchanged word" );
43 # Combine n21 and n21p0
44 my $remaining = $c->reading('n21');
45 $remaining ||= $c->reading('n22'); # one of these should still exist
46 $c->merge_readings( 'n21p0', $remaining, 1 );
47 ok( !$c->reading('n21'), "Reading $remaining is gone" );
48 is( $c->reading('n21p0')->text, 'unto', "Reading n21p0 merged correctly" );
60 my $datafile = 't/data/florilegium_tei_ps.xml';
61 my $tradition = Text::Tradition->new( 'input' => 'TEI',
66 ok( $tradition, "Got a tradition object" );
67 is( scalar $tradition->witnesses, 13, "Found all witnesses" );
68 ok( $tradition->collation, "Tradition has a collation" );
70 my $c = $tradition->collation;
71 is( scalar $c->readings, $READINGS, "Collation has all readings" );
72 is( scalar $c->paths, $PATHS, "Collation has all paths" );
73 is( scalar $c->relationships, 0, "Collation has all relationships" );
75 # Add a few relationships
76 $c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } );
77 $c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } );
78 $c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } );
80 # Now write it to GraphML and parse it again.
82 my $graphml = $c->as_graphml;
83 my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml );
84 is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" );
85 is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" );
86 is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
95 my $cxfile = 't/data/Collatex-16.xml';
96 my $t = Text::Tradition->new(
98 'input' => 'CollateX',
101 my $c = $t->collation;
104 my $table = $c->alignment_table;
105 ok( $c->has_cached_table, "Alignment table was cached" );
106 is( $c->alignment_table, $table, "Cached table returned upon second call" );
108 is( $c->alignment_table, $table, "Cached table retained with no rank change" );
109 $c->add_relationship( 'n24', 'n23', { 'type' => 'spelling' } );
110 isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" );
119 my $cxfile = 't/data/Collatex-16.xml';
120 my $t = Text::Tradition->new(
122 'input' => 'CollateX',
125 my $c = $t->collation;
127 my @common = $c->calculate_common_readings();
128 is( scalar @common, 8, "Found correct number of common readings" );
129 my @marked = sort $c->common_readings();
130 is( scalar @common, 8, "All common readings got marked as such" );
131 my @expected = qw/ n1 n11 n16 n19 n20 n5 n6 n7 /;
132 is_deeply( \@marked, \@expected, "Found correct list of common readings" );
141 my $cxfile = 't/data/Collatex-16.xml';
142 my $t = Text::Tradition->new(
144 'input' => 'CollateX',
147 my $c = $t->collation;
149 is( $c->common_predecessor( 'n24', 'n23' )->id,
150 'n20', "Found correct common predecessor" );
151 is( $c->common_successor( 'n24', 'n23' )->id,
152 '__END__', "Found correct common successor" );
154 is( $c->common_predecessor( 'n19', 'n17' )->id,
155 'n16', "Found correct common predecessor for readings on same path" );
156 is( $c->common_successor( 'n21', 'n10' )->id,
157 '__END__', "Found correct common successor for readings on same path" );