text_alignment 0.2.9 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class TextAlignment
2
- VERSION = '0.2.9'
2
+ VERSION = '0.3.14'
3
3
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = 'Ruby class for aligning two character strings'
13
13
  gem.license = 'MIT'
14
14
 
15
- gem.files = `git ls-files`.split($/)
15
+ gem.files = `git ls-files`.split($/) - `git ls-files spec`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text_alignment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jin-Dong Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-dictionary
@@ -75,6 +75,7 @@ files:
75
75
  - README.md
76
76
  - bin/align_annotations
77
77
  - lib/text_alignment.rb
78
+ - lib/text_alignment/anchor_finder.rb
78
79
  - lib/text_alignment/approximate_fit.rb
79
80
  - lib/text_alignment/find_divisions.rb
80
81
  - lib/text_alignment/glcs_alignment.rb
@@ -85,13 +86,9 @@ files:
85
86
  - lib/text_alignment/lcs_comparison.rb
86
87
  - lib/text_alignment/lcs_min.rb
87
88
  - lib/text_alignment/mappings.rb
89
+ - lib/text_alignment/mixed_alignment.rb
88
90
  - lib/text_alignment/text_alignment.rb
89
91
  - lib/text_alignment/version.rb
90
- - spec/spec_helper.rb
91
- - spec/text_alignment/glcs_alignment_spec.rb
92
- - spec/text_alignment/lcs_alignment_spec.rb
93
- - spec/text_alignment/lcs_comparision_spec.rb
94
- - spec/text_alignment/text_alignment_spec.rb
95
92
  - text_alignment.gemspec
96
93
  homepage:
97
94
  licenses:
@@ -116,9 +113,4 @@ rubygems_version: 3.0.8
116
113
  signing_key:
117
114
  specification_version: 4
118
115
  summary: Ruby class for aligning two character strings
119
- test_files:
120
- - spec/spec_helper.rb
121
- - spec/text_alignment/glcs_alignment_spec.rb
122
- - spec/text_alignment/lcs_alignment_spec.rb
123
- - spec/text_alignment/lcs_comparision_spec.rb
124
- - spec/text_alignment/text_alignment_spec.rb
116
+ test_files: []
@@ -1 +0,0 @@
1
- require 'text_alignment'
@@ -1,302 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe TextAlignment::GLCSAlignment do
4
- context 'for exception handling' do
5
- it 'should raise error for passing of nil strings' do
6
- expect {TextAlignment::GLCSAlignment.new('abc', nil)}.to raise_error
7
- expect {TextAlignment::GLCSAlignment.new(nil, 'abc')}.to raise_error
8
- expect {TextAlignment::GLCSAlignment.new(nil, nil)}.to raise_error
9
- end
10
-
11
- it 'should raise error for passing of nil dictionary' do
12
- expect {TextAlignment::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.new('abc', 'abcxyz')
58
- expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3})
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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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 eq([['-', '-'], ['β', '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::GLCSAlignment.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 eq([['-', '-'], ['β', '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::GLCSAlignment.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 eq([['β', '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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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::GLCSAlignment.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
@@ -1,98 +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
- end
50
-
51
- it 'should detect an addition' do
52
- #012 012345
53
- sa = TextAlignment::LCSAlignment.new('abc', 'xyzabc')
54
- expect(sa.position_map_begin).to eq({0=>3, 1=>4, 2=>5, 3=>6})
55
- expect(sa.position_map_end).to eq({0=>3, 1=>4, 2=>5, 3=>6})
56
- expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
57
- expect(sa.mapped_elements).to eq([])
58
- end
59
-
60
- it 'should detect a variation' do
61
- #012345 01234
62
- sa = TextAlignment::LCSAlignment.new('ijkabc', 'xyabc')
63
- expect(sa.position_map_begin).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
64
- expect(sa.position_map_end).to eq({0=>0, 1=>nil, 2=>nil, 3=>2, 4=>3, 5=>4, 6=>5})
65
- expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
66
- expect(sa.mapped_elements).to eq([['ijk', 'xy']])
67
- end
68
- end
69
-
70
- context 'in the end of a string' do
71
- it 'should detect a deletion' do
72
- #012345 012
73
- sa = TextAlignment::LCSAlignment.new('abcxyz', 'abc')
74
- expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
75
- expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>3, 5=>3, 6=>3})
76
- expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
77
- expect(sa.mapped_elements).to eq([])
78
- end
79
-
80
- it 'should detect an addition' do
81
- #012 012345
82
- sa = TextAlignment::LCSAlignment.new('abc', 'abcxyz')
83
- expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>6})
84
- expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3})
85
- expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
86
- expect(sa.mapped_elements).to eq([])
87
- end
88
-
89
- it 'should detect a variation' do
90
- #012345 01234
91
- sa = TextAlignment::LCSAlignment.new('abcijk', 'abcxy')
92
- expect(sa.position_map_begin).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
93
- expect(sa.position_map_end).to eq({0=>0, 1=>1, 2=>2, 3=>3, 4=>nil, 5=>nil, 6=>5})
94
- expect(sa.common_elements).to eq([['a', 'a'], ['b', 'b'], ['c', 'c']])
95
- expect(sa.mapped_elements).to eq([['ijk', 'xy']])
96
- end
97
- end
98
- end