replace collation relationships whenever we can
[scpubgit/stemmatology.git] / t / text_tradition_collation.t
CommitLineData
0e47f4f6 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
11use Text::Tradition;
12
4e483aa5 13my $cxfile = 't/data/Collatex-16.xml';
14my $t = Text::Tradition->new(
15 'name' => 'inline',
16 'input' => 'CollateX',
17 'file' => $cxfile,
18 );
19my $c = $t->collation;
20
21my $rno = scalar $c->readings;
22# Split n21 for testing purposes
23my $new_r = $c->add_reading( { 'id' => 'n21p0', 'text' => 'un', 'join_next' => 1 } );
24my $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' );
29$c->flatten_ranks();
30ok( $c->reading( 'n21p0' ), "New reading exists" );
31is( scalar $c->readings, $rno, "Reading add offset by flatten_ranks" );
32
33# Combine n3 and n4
34$c->merge_readings( 'n3', 'n4', 1 );
35ok( !$c->reading('n4'), "Reading n4 is gone" );
36is( $c->reading('n3')->text, 'with his', "Reading n3 has both words" );
37
38# Collapse n25 and n26
39$c->merge_readings( 'n25', 'n26' );
40ok( !$c->reading('n26'), "Reading n26 is gone" );
41is( $c->reading('n25')->text, 'rood', "Reading n25 has an unchanged word" );
42
43# Combine n21 and n21p0
44my $remaining = $c->reading('n21');
45$remaining ||= $c->reading('n22'); # one of these should still exist
46$c->merge_readings( 'n21p0', $remaining, 1 );
47ok( !$c->reading('n21'), "Reading $remaining is gone" );
48is( $c->reading('n21p0')->text, 'unto', "Reading n21p0 merged correctly" );
49}
50
51
52
53# =begin testing
54{
55use Text::Tradition;
56
56eefa04 57my $READINGS = 311;
58my $PATHS = 361;
59
60my $datafile = 't/data/florilegium_tei_ps.xml';
61my $tradition = Text::Tradition->new( 'input' => 'TEI',
62 'name' => 'test0',
63 'file' => $datafile,
64 'linear' => 1 );
65
66ok( $tradition, "Got a tradition object" );
67is( scalar $tradition->witnesses, 13, "Found all witnesses" );
68ok( $tradition->collation, "Tradition has a collation" );
69
70my $c = $tradition->collation;
71is( scalar $c->readings, $READINGS, "Collation has all readings" );
72is( scalar $c->paths, $PATHS, "Collation has all paths" );
73is( scalar $c->relationships, 0, "Collation has all relationships" );
74
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' } );
79
80# Now write it to GraphML and parse it again.
81
82my $graphml = $c->as_graphml;
83my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml );
84is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" );
85is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" );
86is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
87}
88
89
90
91# =begin testing
92{
93use Text::Tradition;
94
0e47f4f6 95my $cxfile = 't/data/Collatex-16.xml';
96my $t = Text::Tradition->new(
97 'name' => 'inline',
98 'input' => 'CollateX',
99 'file' => $cxfile,
100 );
101my $c = $t->collation;
4633f9e4 102
b365fbae 103# Make an svg
bfcbcecb 104my $table = $c->alignment_table;
105ok( $c->has_cached_table, "Alignment table was cached" );
106is( $c->alignment_table, $table, "Cached table returned upon second call" );
b365fbae 107$c->calculate_ranks;
bfcbcecb 108is( $c->alignment_table, $table, "Cached table retained with no rank change" );
b365fbae 109$c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } );
bfcbcecb 110isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" );
b365fbae 111}
112
113
114
115# =begin testing
116{
117use Text::Tradition;
118
119my $cxfile = 't/data/Collatex-16.xml';
120my $t = Text::Tradition->new(
121 'name' => 'inline',
122 'input' => 'CollateX',
123 'file' => $cxfile,
124 );
125my $c = $t->collation;
0e47f4f6 126
d4b75f44 127my @common = $c->calculate_common_readings();
128is( scalar @common, 8, "Found correct number of common readings" );
129my @marked = sort $c->common_readings();
130is( scalar @common, 8, "All common readings got marked as such" );
131my @expected = qw/ n1 n12 n16 n19 n20 n5 n6 n7 /;
132is_deeply( \@marked, \@expected, "Found correct list of common readings" );
133}
134
135
136
137# =begin testing
138{
139use Text::Tradition;
140
141my $cxfile = 't/data/Collatex-16.xml';
142my $t = Text::Tradition->new(
143 'name' => 'inline',
144 'input' => 'CollateX',
145 'file' => $cxfile,
146 );
147my $c = $t->collation;
148
4e5a7b2c 149is( $c->common_predecessor( 'n9', 'n23' )->id,
0e47f4f6 150 'n20', "Found correct common predecessor" );
4e5a7b2c 151is( $c->common_successor( 'n9', 'n23' )->id,
0e47f4f6 152 '#END#', "Found correct common successor" );
153
4e5a7b2c 154is( $c->common_predecessor( 'n19', 'n17' )->id,
0e47f4f6 155 'n16', "Found correct common predecessor for readings on same path" );
4e5a7b2c 156is( $c->common_successor( 'n21', 'n26' )->id,
0e47f4f6 157 '#END#', "Found correct common successor for readings on same path" );
158}
159
160
161
162
1631;