text_alignment 0.2.9 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/align_annotations +190 -39
- data/lib/text_alignment/anchor_finder.rb +149 -0
- data/lib/text_alignment/approximate_fit.rb +50 -52
- data/lib/text_alignment/find_divisions.rb +198 -200
- data/lib/text_alignment/glcs_alignment.rb +297 -297
- data/lib/text_alignment/glcs_alignment_fast.rb +94 -94
- data/lib/text_alignment/glcs_required.rb +50 -50
- data/lib/text_alignment/lcs_alignment.rb +115 -115
- data/lib/text_alignment/lcs_cdiff.rb +46 -48
- data/lib/text_alignment/lcs_comparison.rb +53 -53
- data/lib/text_alignment/lcs_min.rb +144 -138
- data/lib/text_alignment/mappings.rb +68 -69
- data/lib/text_alignment/mixed_alignment.rb +193 -0
- data/lib/text_alignment/text_alignment.rb +232 -174
- data/lib/text_alignment/version.rb +1 -1
- data/text_alignment.gemspec +1 -1
- metadata +5 -13
- data/spec/spec_helper.rb +0 -1
- data/spec/text_alignment/glcs_alignment_spec.rb +0 -302
- data/spec/text_alignment/lcs_alignment_spec.rb +0 -98
- data/spec/text_alignment/lcs_comparision_spec.rb +0 -322
- data/spec/text_alignment/text_alignment_spec.rb +0 -302
@@ -1,322 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TextAlignment::LCSAlignment do
|
4
|
-
context 'for exception handling' do
|
5
|
-
it 'should raise error for passing of nil strings' do
|
6
|
-
expect {TextAlignment::LCSAlignment.new('abc', nil)}.to raise_error
|
7
|
-
expect {TextAlignment::LCSAlignment.new(nil, 'abc')}.to raise_error
|
8
|
-
expect {TextAlignment::LCSAlignment.new(nil, nil)}.to raise_error
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'in the middle of a string' do
|
13
|
-
it 'should detect a deletion' do
|
14
|
-
#0123456 0123
|
15
|
-
sa = TextAlignment::LCSAlignment.new('abxyzcd', 'abcd')
|
16
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>2, 4=>2, 5=>2, 6=>3, 7=>4})
|
17
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>2, 4=>2, 5=>2, 6=>3, 7=>4})
|
18
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
19
|
-
expect(sa.mapped_elements).to eq([])
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should detect an addition' do
|
23
|
-
#0123 0123456
|
24
|
-
sa = TextAlignment::LCSAlignment.new('abcd', 'abxyzcd')
|
25
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>6, 4=>7})
|
26
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>6, 4=>7})
|
27
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
28
|
-
expect(sa.mapped_elements).to eq([])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should detect a variation' do
|
32
|
-
#0123456 012345
|
33
|
-
sa = TextAlignment::LCSAlignment.new('abijkcd', 'abxycd')
|
34
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>nil, 4=>nil, 5=>4, 6=>5, 7=>6})
|
35
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>nil, 4=>nil, 5=>4, 6=>5, 7=>6})
|
36
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
37
|
-
expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# context 'in the beginning of a string' do
|
42
|
-
# it 'should detect a deletion' do
|
43
|
-
# #012345 012
|
44
|
-
# sa = TextAlignment::LCSAlignment.new('xyzabc', 'abc')
|
45
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>0, 2=>0, 3=>0, 4=>1, 5=>2, 6=>3})
|
46
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>0, 2=>0, 3=>0, 4=>1, 5=>2, 6=>3})
|
47
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
48
|
-
# expect(sa.mapped_elements).to eq([])
|
49
|
-
# expect(sa.front_overflow).to eq 3
|
50
|
-
# expect(sa.rear_overflow).to eq 0
|
51
|
-
# end
|
52
|
-
|
53
|
-
# it 'should detect an addition' do
|
54
|
-
# #012 012345
|
55
|
-
# sa = TextAlignment::LCSAlignment.new('abc', 'xyzabc')
|
56
|
-
# expect(sa.position_map_begin).to eq({0=>3, 1=>4, 2=>5, 3=>6})
|
57
|
-
# expect(sa.position_map_end).to eq({0=>3, 1=>4, 2=>5, 3=>6})
|
58
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
59
|
-
# expect(sa.mapped_elements).to eq([])
|
60
|
-
# expect(sa.front_overflow).to eq -3
|
61
|
-
# expect(sa.rear_overflow).to eq 0
|
62
|
-
# end
|
63
|
-
|
64
|
-
# it 'should detect a variation' do
|
65
|
-
# #012345 01234
|
66
|
-
# sa = TextAlignment::LCSAlignment.new('ijkabc', 'xyabc')
|
67
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
|
68
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
|
69
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
70
|
-
# expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
71
|
-
# expect(sa.front_overflow).to eq 1
|
72
|
-
# expect(sa.rear_overflow).to eq 0
|
73
|
-
# end
|
74
|
-
# end
|
75
|
-
|
76
|
-
# context 'in the end of a string' do
|
77
|
-
# it 'should detect a deletion' do
|
78
|
-
# #012345 012
|
79
|
-
# sa = TextAlignment::LCSAlignment.new('abcxyz', 'abc')
|
80
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
|
81
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
|
82
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
83
|
-
# expect(sa.mapped_elements).to eq([])
|
84
|
-
# expect(sa.front_overflow).to eq 0
|
85
|
-
# expect(sa.rear_overflow).to eq 3
|
86
|
-
# end
|
87
|
-
|
88
|
-
# it 'should detect an addition' do
|
89
|
-
# #012 012345
|
90
|
-
# sa = TextAlignment::LCSAlignment.new('abc', 'abcxyz')
|
91
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3})
|
92
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3})
|
93
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
94
|
-
# expect(sa.mapped_elements).to eq([])
|
95
|
-
# expect(sa.front_overflow).to eq 0
|
96
|
-
# expect(sa.rear_overflow).to eq -3
|
97
|
-
# end
|
98
|
-
|
99
|
-
# it 'should detect a variation' do
|
100
|
-
# #012345 01234
|
101
|
-
# sa = TextAlignment::LCSAlignment.new('abcijk', 'abcxy')
|
102
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
|
103
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
|
104
|
-
# expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
105
|
-
# expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
106
|
-
# expect(sa.front_overflow).to eq 0
|
107
|
-
# expect(sa.rear_overflow).to eq 1
|
108
|
-
# end
|
109
|
-
# end
|
110
|
-
|
111
|
-
# context ', with a dictionary with the first entry, ' do
|
112
|
-
# before(:all) do
|
113
|
-
# @dictionary = [["β", "beta"]]
|
114
|
-
# end
|
115
|
-
# it 'should handle consecutive unicode spellouts in the middle of a string' do
|
116
|
-
# #0123 01234567890
|
117
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
118
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
119
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
120
|
-
# expect(sa.common_elements).to eq([['-', '-'], ['β', 'beta'], ['-', '-']])
|
121
|
-
# expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
122
|
-
# expect(sa.front_overflow).to eq 0
|
123
|
-
# expect(sa.rear_overflow).to eq 0
|
124
|
-
# end
|
125
|
-
|
126
|
-
# it 'should handle consecutive unicode spellouts in the end of a string' do
|
127
|
-
# #012 0123456789
|
128
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ', '-betakappa', @dictionary)
|
129
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
130
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
131
|
-
# expect(sa.common_elements).to eq([['-', '-'], ['β', 'beta']])
|
132
|
-
# expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
133
|
-
# expect(sa.front_overflow).to eq 0
|
134
|
-
# expect(sa.rear_overflow).to eq -4
|
135
|
-
# end
|
136
|
-
|
137
|
-
# it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
138
|
-
# #012 0123456789
|
139
|
-
# sa = TextAlignment::LCSAlignment.new('βκ-', 'betakappa-', @dictionary)
|
140
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
141
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
142
|
-
# expect(sa.common_elements).to eq([['β', 'beta'], ['-', '-']])
|
143
|
-
# expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
144
|
-
# expect(sa.front_overflow).to eq 0
|
145
|
-
# expect(sa.rear_overflow).to eq 0
|
146
|
-
# end
|
147
|
-
|
148
|
-
# it 'should handle consecutive unicode restorations in the middle of a string' do
|
149
|
-
# #01234567890 0123
|
150
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
151
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
152
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
153
|
-
# expect(sa.common_elements).to eq([['-', '-'], ['beta', 'β'], ['-', '-']])
|
154
|
-
# expect(sa.mapped_elements).to eq([['kappa', 'κ']])
|
155
|
-
# end
|
156
|
-
|
157
|
-
# it 'should handle consecutive unicode restorations in the beginning of a string' do
|
158
|
-
# #0123456789 012
|
159
|
-
# sa = TextAlignment::LCSAlignment.new('betakappa-', 'βκ-', @dictionary)
|
160
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
161
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
162
|
-
# expect(sa.common_elements).to eq([['beta', 'β'], ['-', '-']])
|
163
|
-
# expect(sa.mapped_elements).to eq([['kappa', 'κ']])
|
164
|
-
# end
|
165
|
-
|
166
|
-
# it 'should handle consecutive unicode restorations in the end of a string' do
|
167
|
-
# #0123456789 012
|
168
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa', '-βκ', @dictionary)
|
169
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
170
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
171
|
-
# expect(sa.common_elements).to eq([['-', '-'], ['beta', 'β']])
|
172
|
-
# expect(sa.mapped_elements).to eq([['kappa', 'κ']])
|
173
|
-
# end
|
174
|
-
# end
|
175
|
-
|
176
|
-
# context ', with a dictionary with the second entry, ' do
|
177
|
-
# before(:all) do
|
178
|
-
# @dictionary = [["κ", "kappa"]]
|
179
|
-
# end
|
180
|
-
# it 'should handle consecutive unicode spellouts in the middle of a string' do
|
181
|
-
# #0123 01234567890
|
182
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
183
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
184
|
-
# end
|
185
|
-
|
186
|
-
# it 'should handle consecutive unicode spellouts in the end of a string' do
|
187
|
-
# #012 0123456789
|
188
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ', '-betakappa', @dictionary)
|
189
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
190
|
-
# end
|
191
|
-
|
192
|
-
# it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
193
|
-
# #012 0123456789
|
194
|
-
# sa = TextAlignment::LCSAlignment.new('βκ-', 'betakappa-', @dictionary)
|
195
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
196
|
-
# end
|
197
|
-
|
198
|
-
# it 'should handle consecutive unicode restorations in the middle of a string' do
|
199
|
-
# #01234567890 0123
|
200
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
201
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
202
|
-
# end
|
203
|
-
|
204
|
-
# it 'should handle consecutive unicode restorations in the beginning of a string' do
|
205
|
-
# #0123456789 012
|
206
|
-
# sa = TextAlignment::LCSAlignment.new('betakappa-', 'βκ-', @dictionary)
|
207
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
208
|
-
# end
|
209
|
-
|
210
|
-
# it 'should handle consecutive unicode restorations in the end of a string' do
|
211
|
-
# #0123456789 012
|
212
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa', '-βκ', @dictionary)
|
213
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
214
|
-
# end
|
215
|
-
# end
|
216
|
-
|
217
|
-
# context ', with a dictionary with both entries, ' do
|
218
|
-
# before(:all) do
|
219
|
-
# @dictionary = [["β", "beta"], ["κ", "kappa"]]
|
220
|
-
# end
|
221
|
-
# it 'should handle consecutive unicode spellouts in the middle of a string' do
|
222
|
-
# #0123 01234567890
|
223
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
224
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
225
|
-
# end
|
226
|
-
|
227
|
-
# it 'should handle consecutive unicode spellouts in the end of a string' do
|
228
|
-
# #012 0123456789
|
229
|
-
# sa = TextAlignment::LCSAlignment.new('-βκ', '-betakappa', @dictionary)
|
230
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
231
|
-
# end
|
232
|
-
|
233
|
-
# it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
234
|
-
# #012 0123456789
|
235
|
-
# sa = TextAlignment::LCSAlignment.new('βκ-', 'betakappa-', @dictionary)
|
236
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
237
|
-
# end
|
238
|
-
|
239
|
-
# it 'should handle consecutive unicode restorations in the middle of a string' do
|
240
|
-
# #01234567890 0123
|
241
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
242
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
243
|
-
# end
|
244
|
-
|
245
|
-
# it 'should handle consecutive unicode restorations in the beginning of a string' do
|
246
|
-
# #0123456789 012
|
247
|
-
# sa = TextAlignment::LCSAlignment.new('betakappa-', 'βκ-', @dictionary)
|
248
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
249
|
-
# end
|
250
|
-
|
251
|
-
# it 'should handle consecutive unicode restorations in the end of a string' do
|
252
|
-
# #0123456789 012
|
253
|
-
# sa = TextAlignment::LCSAlignment.new('-betakappa', '-βκ', @dictionary)
|
254
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
255
|
-
# end
|
256
|
-
# end
|
257
|
-
|
258
|
-
# context ', with a dictionary, ' do
|
259
|
-
# before(:all) do
|
260
|
-
# @dictionary = [["β", "beta"], ["κ", "kappa"]]
|
261
|
-
# end
|
262
|
-
|
263
|
-
# it 'should handle a unicode spellout followed by addition' do
|
264
|
-
# #012 012345678
|
265
|
-
# sa = TextAlignment::LCSAlignment.new("-β-", "-beta***-", @dictionary)
|
266
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>8, 3=>9})
|
267
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>9})
|
268
|
-
# end
|
269
|
-
|
270
|
-
# it 'should handle a unicode retoration followed by addition' do
|
271
|
-
# #012345 012345
|
272
|
-
# sa = TextAlignment::LCSAlignment.new("-beta-", "-β***-", @dictionary)
|
273
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
274
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>6})
|
275
|
-
# end
|
276
|
-
|
277
|
-
# it 'should handle a unicode spellout followed by deletion' do
|
278
|
-
# #012345 012345
|
279
|
-
# sa = TextAlignment::LCSAlignment.new("-β***-", "-beta-", @dictionary)
|
280
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>5, 4=>5, 5=>5, 6=>6})
|
281
|
-
# end
|
282
|
-
|
283
|
-
# it 'should handle a unicode retoration followed by deletion' do
|
284
|
-
# #012345678 0123
|
285
|
-
# sa = TextAlignment::LCSAlignment.new("-beta***-", "-β-", @dictionary)
|
286
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>2, 7=>2, 8=>2, 9=>3})
|
287
|
-
# end
|
288
|
-
|
289
|
-
# it 'should handle a unicode spellout following addition' do
|
290
|
-
# #012 012345678
|
291
|
-
# sa = TextAlignment::LCSAlignment.new("-β-", "-***beta-", @dictionary)
|
292
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>8, 3=>9})
|
293
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>8, 3=>9})
|
294
|
-
# end
|
295
|
-
|
296
|
-
# it 'should handle a unicode retoration following addition' do
|
297
|
-
# #012345 012345
|
298
|
-
# sa = TextAlignment::LCSAlignment.new("-beta-", "-***β-", @dictionary)
|
299
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
300
|
-
# expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
301
|
-
# end
|
302
|
-
|
303
|
-
# it 'should handle a unicode spellout following deletion' do
|
304
|
-
# #012345 012345
|
305
|
-
# sa = TextAlignment::LCSAlignment.new("-***β-", "-beta-", @dictionary)
|
306
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>1, 3=>1, 4=>1, 5=>5, 6=>6})
|
307
|
-
# end
|
308
|
-
|
309
|
-
# it 'should handle a unicode retoration following deletion' do
|
310
|
-
# #012345678 012
|
311
|
-
# sa = TextAlignment::LCSAlignment.new("-***beta-", "-β-", @dictionary)
|
312
|
-
# expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>1, 3=>1, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>2, 9=>3})
|
313
|
-
# end
|
314
|
-
|
315
|
-
# end
|
316
|
-
|
317
|
-
# from_text = "-beta***-"
|
318
|
-
# to_text = "-##β-"
|
319
|
-
|
320
|
-
# from_text = "TGF-beta-induced"
|
321
|
-
# to_text = "TGF-β–induced"
|
322
|
-
end
|
@@ -1,302 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TextAlignment::TextAlignment do
|
4
|
-
context 'for exception handling' do
|
5
|
-
it 'should raise error for passing of nil strings' do
|
6
|
-
expect {TextAlignment::TextAlignment.new('abc', nil)}.to raise_error
|
7
|
-
expect {TextAlignment::TextAlignment.new(nil, 'abc')}.to raise_error
|
8
|
-
expect {TextAlignment::TextAlignment.new(nil, nil)}.to raise_error
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should raise error for passing of nil dictionary' do
|
12
|
-
expect {TextAlignment::TextAlignment.new('abc', 'abc', nil)}.to raise_error
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'in the beginning of a string' do
|
17
|
-
it 'should detect a deletion' do
|
18
|
-
#012345 012
|
19
|
-
sa = TextAlignment::TextAlignment.new('xyzabc', 'abc')
|
20
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>0, 2=>0, 3=>0, 4=>1, 5=>2, 6=>3})
|
21
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>0, 2=>0, 3=>0, 4=>1, 5=>2, 6=>3})
|
22
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
23
|
-
expect(sa.mapped_elements).to eq([])
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should detect an addition' do
|
27
|
-
#012 012345
|
28
|
-
sa = TextAlignment::TextAlignment.new('abc', 'xyzabc')
|
29
|
-
expect(sa.position_map_begin).to eq({0=>3, 1=>4, 2=>5, 3=>6})
|
30
|
-
expect(sa.position_map_end).to eq({0=>3, 1=>4, 2=>5, 3=>6})
|
31
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
32
|
-
expect(sa.mapped_elements).to eq([])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should detect a variation' do
|
36
|
-
#012345 01234
|
37
|
-
sa = TextAlignment::TextAlignment.new('ijkabc', 'xyabc')
|
38
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
|
39
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
|
40
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
41
|
-
expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'in the end of a string' do
|
46
|
-
it 'should detect a deletion' do
|
47
|
-
#012345 012
|
48
|
-
sa = TextAlignment::TextAlignment.new('abcxyz', 'abc')
|
49
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
|
50
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
|
51
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
52
|
-
expect(sa.mapped_elements).to eq([])
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should detect an addition' do
|
56
|
-
#012 012345
|
57
|
-
sa = TextAlignment::TextAlignment.new('abc', 'abcxyz')
|
58
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>6})
|
59
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3})
|
60
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
61
|
-
expect(sa.mapped_elements).to eq([])
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should detect a variation' do
|
65
|
-
#012345 01234
|
66
|
-
sa = TextAlignment::TextAlignment.new('abcijk', 'abcxy')
|
67
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
|
68
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
|
69
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
|
70
|
-
expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'in the middle of a string' do
|
75
|
-
it 'should detect a deletion' do
|
76
|
-
#0123456 0123
|
77
|
-
sa = TextAlignment::TextAlignment.new('abxyzcd', 'abcd')
|
78
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>2, 4=>2, 5=>2, 6=>3, 7=>4})
|
79
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>2, 4=>2, 5=>2, 6=>3, 7=>4})
|
80
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
81
|
-
expect(sa.mapped_elements).to eq([])
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should detect an addition' do
|
85
|
-
#0123 0123456
|
86
|
-
sa = TextAlignment::TextAlignment.new('abcd', 'abxyzcd')
|
87
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>6, 4=>7})
|
88
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>6, 4=>7})
|
89
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
90
|
-
expect(sa.mapped_elements).to eq([])
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should detect a variation' do
|
94
|
-
#0123456 012345
|
95
|
-
sa = TextAlignment::TextAlignment.new('abijkcd', 'abxycd')
|
96
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>nil, 4=>nil, 5=>4, 6=>5, 7=>6})
|
97
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>nil, 4=>nil, 5=>4, 6=>5, 7=>6})
|
98
|
-
expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd']])
|
99
|
-
expect(sa.mapped_elements).to eq([['ijk', 'xy']])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context ', with a dictionary with the first entry, ' do
|
104
|
-
before(:all) do
|
105
|
-
@dictionary = [["β", "beta"]]
|
106
|
-
end
|
107
|
-
it 'should handle consecutive unicode spellouts in the middle of a string' do
|
108
|
-
#0123 01234567890
|
109
|
-
sa = TextAlignment::TextAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
110
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
111
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
112
|
-
expect(sa.common_elements).to match_array([['-', '-'], ['β', 'beta'], ['-', '-']])
|
113
|
-
expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should handle consecutive unicode spellouts in the end of a string' do
|
117
|
-
#012 0123456789
|
118
|
-
sa = TextAlignment::TextAlignment.new('-βκ', '-betakappa', @dictionary)
|
119
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
120
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
121
|
-
expect(sa.common_elements).to match_array([['-', '-'], ['β', 'beta']])
|
122
|
-
expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
126
|
-
#012 0123456789
|
127
|
-
sa = TextAlignment::TextAlignment.new('βκ-', 'betakappa-', @dictionary)
|
128
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
129
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
130
|
-
expect(sa.common_elements).to match_array([['β', 'beta'], ['-', '-']])
|
131
|
-
expect(sa.mapped_elements).to eq([['κ', 'kappa']])
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should handle consecutive unicode restorations in the middle of a string' do
|
135
|
-
#01234567890 0123
|
136
|
-
sa = TextAlignment::TextAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
137
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
138
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'should handle consecutive unicode restorations in the beginning of a string' do
|
142
|
-
#0123456789 012
|
143
|
-
sa = TextAlignment::TextAlignment.new('betakappa-', 'βκ-', @dictionary)
|
144
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
145
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should handle consecutive unicode restorations in the end of a string' do
|
149
|
-
#0123456789 012
|
150
|
-
sa = TextAlignment::TextAlignment.new('-betakappa', '-βκ', @dictionary)
|
151
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
152
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context ', with a dictionary with the second entry, ' do
|
157
|
-
before(:all) do
|
158
|
-
@dictionary = [["κ", "kappa"]]
|
159
|
-
end
|
160
|
-
it 'should handle consecutive unicode spellouts in the middle of a string' do
|
161
|
-
#0123 01234567890
|
162
|
-
sa = TextAlignment::TextAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
163
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should handle consecutive unicode spellouts in the end of a string' do
|
167
|
-
#012 0123456789
|
168
|
-
sa = TextAlignment::TextAlignment.new('-βκ', '-betakappa', @dictionary)
|
169
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
173
|
-
#012 0123456789
|
174
|
-
sa = TextAlignment::TextAlignment.new('βκ-', 'betakappa-', @dictionary)
|
175
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should handle consecutive unicode restorations in the middle of a string' do
|
179
|
-
#01234567890 0123
|
180
|
-
sa = TextAlignment::TextAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
181
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'should handle consecutive unicode restorations in the beginning of a string' do
|
185
|
-
#0123456789 012
|
186
|
-
sa = TextAlignment::TextAlignment.new('betakappa-', 'βκ-', @dictionary)
|
187
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'should handle consecutive unicode restorations in the end of a string' do
|
191
|
-
#0123456789 012
|
192
|
-
sa = TextAlignment::TextAlignment.new('-betakappa', '-βκ', @dictionary)
|
193
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context ', with a dictionary with both entries, ' do
|
198
|
-
before(:all) do
|
199
|
-
@dictionary = [["β", "beta"], ["κ", "kappa"]]
|
200
|
-
end
|
201
|
-
it 'should handle consecutive unicode spellouts in the middle of a string' do
|
202
|
-
#0123 01234567890
|
203
|
-
sa = TextAlignment::TextAlignment.new('-βκ-', '-betakappa-', @dictionary)
|
204
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10, 4=>11})
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'should handle consecutive unicode spellouts in the end of a string' do
|
208
|
-
#012 0123456789
|
209
|
-
sa = TextAlignment::TextAlignment.new('-βκ', '-betakappa', @dictionary)
|
210
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>10})
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'should handle consecutive unicode spellouts in the beginning of a string' do
|
214
|
-
#012 0123456789
|
215
|
-
sa = TextAlignment::TextAlignment.new('βκ-', 'betakappa-', @dictionary)
|
216
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>9, 3=>10})
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'should handle consecutive unicode restorations in the middle of a string' do
|
220
|
-
#01234567890 0123
|
221
|
-
sa = TextAlignment::TextAlignment.new('-betakappa-', '-βκ-', @dictionary)
|
222
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3, 11=>4})
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'should handle consecutive unicode restorations in the beginning of a string' do
|
226
|
-
#0123456789 012
|
227
|
-
sa = TextAlignment::TextAlignment.new('betakappa-', 'βκ-', @dictionary)
|
228
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>nil, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>nil, 9=>2, 10=>3})
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'should handle consecutive unicode restorations in the end of a string' do
|
232
|
-
#0123456789 012
|
233
|
-
sa = TextAlignment::TextAlignment.new('-betakappa', '-βκ', @dictionary)
|
234
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>nil, 7=>nil, 8=>nil, 9=>nil, 10=>3})
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context ', with a dictionary, ' do
|
239
|
-
before(:all) do
|
240
|
-
@dictionary = [["β", "beta"], ["κ", "kappa"]]
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'should handle a unicode spellout followed by addition' do
|
244
|
-
#012 012345678
|
245
|
-
sa = TextAlignment::TextAlignment.new("-β-", "-beta***-", @dictionary)
|
246
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>8, 3=>9})
|
247
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>5, 3=>9})
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'should handle a unicode retoration followed by addition' do
|
251
|
-
#012345 012345
|
252
|
-
sa = TextAlignment::TextAlignment.new("-beta-", "-β***-", @dictionary)
|
253
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
254
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>6})
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should handle a unicode spellout followed by deletion' do
|
258
|
-
#012345 012345
|
259
|
-
sa = TextAlignment::TextAlignment.new("-β***-", "-beta-", @dictionary)
|
260
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>5, 3=>5, 4=>5, 5=>5, 6=>6})
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'should handle a unicode retoration followed by deletion' do
|
264
|
-
#012345678 0123
|
265
|
-
sa = TextAlignment::TextAlignment.new("-beta***-", "-β-", @dictionary)
|
266
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>2, 6=>2, 7=>2, 8=>2, 9=>3})
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'should handle a unicode spellout following addition' do
|
270
|
-
#012 012345678
|
271
|
-
sa = TextAlignment::TextAlignment.new("-β-", "-***beta-", @dictionary)
|
272
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>8, 3=>9})
|
273
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>8, 3=>9})
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'should handle a unicode retoration following addition' do
|
277
|
-
#012345 012345
|
278
|
-
sa = TextAlignment::TextAlignment.new("-beta-", "-***β-", @dictionary)
|
279
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>4, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
280
|
-
expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>nil, 3=>nil, 4=>nil, 5=>5, 6=>6})
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'should handle a unicode spellout following deletion' do
|
284
|
-
#012345 012345
|
285
|
-
sa = TextAlignment::TextAlignment.new("-***β-", "-beta-", @dictionary)
|
286
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>1, 3=>1, 4=>1, 5=>5, 6=>6})
|
287
|
-
end
|
288
|
-
|
289
|
-
it 'should handle a unicode retoration following deletion' do
|
290
|
-
#012345678 012
|
291
|
-
sa = TextAlignment::TextAlignment.new("-***beta-", "-β-", @dictionary)
|
292
|
-
expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>1, 3=>1, 4=>1, 5=>nil, 6=>nil, 7=>nil, 8=>2, 9=>3})
|
293
|
-
end
|
294
|
-
|
295
|
-
end
|
296
|
-
|
297
|
-
from_text = "-beta***-"
|
298
|
-
to_text = "-##β-"
|
299
|
-
|
300
|
-
from_text = "TGF-beta-induced"
|
301
|
-
to_text = "TGF-β–induced"
|
302
|
-
end
|