Commit | Line | Data |
0e47f4f6 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
11 | use Text::Tradition; |
12 | |
4e483aa5 |
13 | my $cxfile = 't/data/Collatex-16.xml'; |
14 | my $t = Text::Tradition->new( |
15 | 'name' => 'inline', |
16 | 'input' => 'CollateX', |
17 | 'file' => $cxfile, |
18 | ); |
19 | my $c = $t->collation; |
20 | |
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' ); |
29 | $c->flatten_ranks(); |
30 | ok( $c->reading( 'n21p0' ), "New reading exists" ); |
31 | is( scalar $c->readings, $rno, "Reading add offset by flatten_ranks" ); |
32 | |
679f17e1 |
33 | # Combine n3 and n4 ( with his ) |
4e483aa5 |
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" ); |
37 | |
679f17e1 |
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" ); |
4e483aa5 |
42 | |
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" ); |
49 | } |
50 | |
51 | |
52 | |
53 | # =begin testing |
54 | { |
55 | use Text::Tradition; |
951ddfe8 |
56 | use TryCatch; |
4e483aa5 |
57 | |
56eefa04 |
58 | my $READINGS = 311; |
59 | my $PATHS = 361; |
60 | |
61 | my $datafile = 't/data/florilegium_tei_ps.xml'; |
62 | my $tradition = Text::Tradition->new( 'input' => 'TEI', |
63 | 'name' => 'test0', |
64 | 'file' => $datafile, |
65 | 'linear' => 1 ); |
66 | |
67 | ok( $tradition, "Got a tradition object" ); |
68 | is( scalar $tradition->witnesses, 13, "Found all witnesses" ); |
69 | ok( $tradition->collation, "Tradition has a collation" ); |
70 | |
71 | my $c = $tradition->collation; |
72 | is( scalar $c->readings, $READINGS, "Collation has all readings" ); |
73 | is( scalar $c->paths, $PATHS, "Collation has all paths" ); |
74 | is( scalar $c->relationships, 0, "Collation has all relationships" ); |
75 | |
76 | # Add a few relationships |
77 | $c->add_relationship( 'w123', 'w125', { 'type' => 'collated' } ); |
78 | $c->add_relationship( 'w193', 'w196', { 'type' => 'collated' } ); |
79 | $c->add_relationship( 'w257', 'w262', { 'type' => 'transposition' } ); |
80 | |
81 | # Now write it to GraphML and parse it again. |
82 | |
83 | my $graphml = $c->as_graphml; |
84 | my $st = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml ); |
85 | is( scalar $st->collation->readings, $READINGS, "Reparsed collation has all readings" ); |
86 | is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" ); |
87 | is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" ); |
2a812726 |
88 | |
9fef629b |
89 | # Now add a stemma, write to GraphML, and look at the output. |
951ddfe8 |
90 | my $SKIP_STEMMA; |
91 | try { |
92 | $tradition->enable_stemmata; |
93 | } catch { |
94 | $SKIP_STEMMA = 1; |
95 | } |
96 | SKIP: { |
97 | skip "Analysis module not present", 3 if $SKIP_STEMMA; |
98 | my $stemma = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' ); |
99 | is( ref( $stemma ), 'Text::Tradition::Stemma', "Parsed dotfile into stemma" ); |
100 | is( $tradition->stemmata, 1, "Tradition now has the stemma" ); |
101 | $graphml = $c->as_graphml; |
102 | like( $graphml, qr/digraph/, "Digraph declaration exists in GraphML" ); |
103 | } |
9fef629b |
104 | |
105 | # Now add a user, write to GraphML, and look at the output. |
106 | unlike( $graphml, qr/testuser/, "Test user name does not exist in GraphML yet" ); |
107 | my $testuser = Text::Tradition::User->new( |
108 | id => 'testuser', password => 'testpass' ); |
109 | is( ref( $testuser ), 'Text::Tradition::User', "Created test user object" ); |
110 | $testuser->add_tradition( $tradition ); |
111 | is( $tradition->user->id, $testuser->id, "Tradition assigned to test user" ); |
112 | $graphml = $c->as_graphml; |
113 | like( $graphml, qr/testuser/, "Test user name now exists in GraphML" ); |
56eefa04 |
114 | } |
115 | |
116 | |
117 | |
118 | # =begin testing |
119 | { |
120 | use Text::Tradition; |
121 | |
0e47f4f6 |
122 | my $cxfile = 't/data/Collatex-16.xml'; |
123 | my $t = Text::Tradition->new( |
124 | 'name' => 'inline', |
125 | 'input' => 'CollateX', |
126 | 'file' => $cxfile, |
127 | ); |
128 | my $c = $t->collation; |
4633f9e4 |
129 | |
b365fbae |
130 | # Make an svg |
bfcbcecb |
131 | my $table = $c->alignment_table; |
132 | ok( $c->has_cached_table, "Alignment table was cached" ); |
133 | is( $c->alignment_table, $table, "Cached table returned upon second call" ); |
b365fbae |
134 | $c->calculate_ranks; |
bfcbcecb |
135 | is( $c->alignment_table, $table, "Cached table retained with no rank change" ); |
679f17e1 |
136 | $c->add_relationship( 'n24', 'n23', { 'type' => 'spelling' } ); |
bfcbcecb |
137 | isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" ); |
b365fbae |
138 | } |
139 | |
140 | |
141 | |
142 | # =begin testing |
143 | { |
144 | use Text::Tradition; |
145 | |
146 | my $cxfile = 't/data/Collatex-16.xml'; |
147 | my $t = Text::Tradition->new( |
148 | 'name' => 'inline', |
149 | 'input' => 'CollateX', |
150 | 'file' => $cxfile, |
151 | ); |
152 | my $c = $t->collation; |
0e47f4f6 |
153 | |
d4b75f44 |
154 | my @common = $c->calculate_common_readings(); |
155 | is( scalar @common, 8, "Found correct number of common readings" ); |
156 | my @marked = sort $c->common_readings(); |
157 | is( scalar @common, 8, "All common readings got marked as such" ); |
679f17e1 |
158 | my @expected = qw/ n1 n11 n16 n19 n20 n5 n6 n7 /; |
d4b75f44 |
159 | is_deeply( \@marked, \@expected, "Found correct list of common readings" ); |
160 | } |
161 | |
162 | |
163 | |
164 | # =begin testing |
165 | { |
166 | use Text::Tradition; |
167 | |
168 | my $cxfile = 't/data/Collatex-16.xml'; |
169 | my $t = Text::Tradition->new( |
170 | 'name' => 'inline', |
171 | 'input' => 'CollateX', |
172 | 'file' => $cxfile, |
173 | ); |
174 | my $c = $t->collation; |
175 | |
679f17e1 |
176 | is( $c->common_predecessor( 'n24', 'n23' )->id, |
0e47f4f6 |
177 | 'n20', "Found correct common predecessor" ); |
679f17e1 |
178 | is( $c->common_successor( 'n24', 'n23' )->id, |
10e4b1ac |
179 | '__END__', "Found correct common successor" ); |
0e47f4f6 |
180 | |
4e5a7b2c |
181 | is( $c->common_predecessor( 'n19', 'n17' )->id, |
0e47f4f6 |
182 | 'n16', "Found correct common predecessor for readings on same path" ); |
679f17e1 |
183 | is( $c->common_successor( 'n21', 'n10' )->id, |
10e4b1ac |
184 | '__END__', "Found correct common successor for readings on same path" ); |
0e47f4f6 |
185 | } |
186 | |
187 | |
188 | |
189 | |
190 | 1; |