text_alignment 0.11.10 → 0.12.1
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/.gitignore +1 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +19 -17
- data/README.md +3 -3
- data/lib/text_alignment/char_mapping.rb +21 -2
- data/lib/text_alignment/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '097a3da5324e29b872a7927e2725ce82120f328ce1961cb24aaa5e058cf1b265'
|
|
4
|
+
data.tar.gz: 727bcfbffe4c30535a3b0bd01f4d14cdd1f4ccf64c5f337549da116e484e5e35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0bb88bc2f353bca72b1cc1488063c3ac3d9f3164c3d877bbef8b17876311a99f08143fced8d8ccaa7283cce1b4e6a1ba265435ef71d6c30979da0a5045462290
|
|
7
|
+
data.tar.gz: ef1a61192ade8cabe0b8960619f3200e1312b3cb6766d4b4dfc4a4685ab8af8397c9647cbc6e50cc6047b5ca4a2daaf7b47e669655616082fa99c06f6d3f1e26
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
|
-
ruby '2.
|
|
2
|
+
ruby '3.2.2'
|
|
3
3
|
|
|
4
|
-
gem 'diff-lcs'
|
|
5
|
-
gem 'ruby-dictionary'
|
|
6
|
-
gem 'string-similarity'
|
|
4
|
+
gem 'diff-lcs'
|
|
5
|
+
gem 'ruby-dictionary'
|
|
6
|
+
gem 'string-similarity'
|
|
7
7
|
|
|
8
8
|
group :test do
|
|
9
9
|
gem 'rspec', '~>3.0'
|
data/Gemfile.lock
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: https://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
diff-lcs (1.
|
|
5
|
-
rspec (3.
|
|
6
|
-
rspec-core (~> 3.
|
|
7
|
-
rspec-expectations (~> 3.
|
|
8
|
-
rspec-mocks (~> 3.
|
|
9
|
-
rspec-core (3.
|
|
10
|
-
rspec-support (~> 3.
|
|
11
|
-
rspec-expectations (3.
|
|
4
|
+
diff-lcs (1.5.0)
|
|
5
|
+
rspec (3.12.0)
|
|
6
|
+
rspec-core (~> 3.12.0)
|
|
7
|
+
rspec-expectations (~> 3.12.0)
|
|
8
|
+
rspec-mocks (~> 3.12.0)
|
|
9
|
+
rspec-core (3.12.2)
|
|
10
|
+
rspec-support (~> 3.12.0)
|
|
11
|
+
rspec-expectations (3.12.3)
|
|
12
12
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
13
|
-
rspec-support (~> 3.
|
|
14
|
-
rspec-mocks (3.
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
rspec-support (~> 3.12.0)
|
|
14
|
+
rspec-mocks (3.12.6)
|
|
15
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
16
|
+
rspec-support (~> 3.12.0)
|
|
17
|
+
rspec-support (3.12.1)
|
|
17
18
|
ruby-dictionary (1.1.1)
|
|
18
19
|
string-similarity (2.1.0)
|
|
19
20
|
|
|
20
21
|
PLATFORMS
|
|
21
22
|
ruby
|
|
23
|
+
x86_64-linux
|
|
22
24
|
|
|
23
25
|
DEPENDENCIES
|
|
24
|
-
diff-lcs
|
|
26
|
+
diff-lcs
|
|
25
27
|
rspec (~> 3.0)
|
|
26
|
-
ruby-dictionary
|
|
27
|
-
string-similarity
|
|
28
|
+
ruby-dictionary
|
|
29
|
+
string-similarity
|
|
28
30
|
|
|
29
31
|
RUBY VERSION
|
|
30
|
-
ruby 2.
|
|
32
|
+
ruby 3.2.2p53
|
|
31
33
|
|
|
32
34
|
BUNDLED WITH
|
|
33
|
-
|
|
35
|
+
2.5.1
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TextAlignment
|
|
2
2
|
|
|
3
3
|
It allows to get an optimal alignemnt of two character sequences, e.g., text.
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ It allows to get an optimal alignemnt of two character sequences, e.g., text.
|
|
|
7
7
|
|
|
8
8
|
Add this line to your application's Gemfile:
|
|
9
9
|
|
|
10
|
-
gem '
|
|
10
|
+
gem 'text_alignment'
|
|
11
11
|
|
|
12
12
|
And then execute:
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ And then execute:
|
|
|
15
15
|
|
|
16
16
|
Or install it yourself as:
|
|
17
17
|
|
|
18
|
-
$ gem install
|
|
18
|
+
$ gem install text_alignment
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
## Contributing
|
|
@@ -91,6 +91,8 @@ class TextAlignment::CharMapping
|
|
|
91
91
|
@method_squeeze_ws = method(:squeeze_ws_1!)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
+
@text = _text
|
|
95
|
+
|
|
94
96
|
char_mapping ||= TextAlignment::CHAR_MAPPING.sort{|a, b| b[1].length <=> a[1].length}
|
|
95
97
|
@mapped_text, offset_mapping = enmap_text(_text, char_mapping)
|
|
96
98
|
@index_enmap = offset_mapping.to_h
|
|
@@ -98,11 +100,11 @@ class TextAlignment::CharMapping
|
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
def enmap_position(position)
|
|
101
|
-
@index_enmap[position]
|
|
103
|
+
@index_enmap[position] || raise(ArgumentError, "Unusual position of annotation: #{position}")
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
def demap_position(position)
|
|
105
|
-
@index_demap[position]
|
|
107
|
+
@index_demap[position] || raise(ArgumentError, "Unusual position of annotation: #{position}")
|
|
106
108
|
end
|
|
107
109
|
|
|
108
110
|
def enmap_denotations(denotations)
|
|
@@ -110,6 +112,23 @@ class TextAlignment::CharMapping
|
|
|
110
112
|
|
|
111
113
|
denotations.map do |d|
|
|
112
114
|
d.dup.merge(span:{begin:enmap_position(d[:span][:begin]), end:enmap_position(d[:span][:end])})
|
|
115
|
+
rescue ArgumentError => e
|
|
116
|
+
snippet_begin = d[:span][:begin] - 5
|
|
117
|
+
if snippet_begin < 0
|
|
118
|
+
snippet_begin = 0
|
|
119
|
+
end
|
|
120
|
+
snippet_end = d[:span][:end] + 5
|
|
121
|
+
if snippet_end > @text.length
|
|
122
|
+
snippet_end = @text.length
|
|
123
|
+
end
|
|
124
|
+
snippet = @text[snippet_begin ... d[:span][:begin]] + '[' + @text[d[:span][:begin] ... d[:span][:end]] + ']' + @text[d[:span][:end] ... snippet_end]
|
|
125
|
+
if snippet_begin > 0
|
|
126
|
+
snippet = '...' + snippet
|
|
127
|
+
end
|
|
128
|
+
if snippet_end < @text.length
|
|
129
|
+
snippet = snippet + '...'
|
|
130
|
+
end
|
|
131
|
+
raise ArgumentError, e.message + " (#{snippet})"
|
|
113
132
|
end
|
|
114
133
|
end
|
|
115
134
|
|
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.
|
|
4
|
+
version: 0.12.1
|
|
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:
|
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-dictionary
|
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
111
111
|
- !ruby/object:Gem::Version
|
|
112
112
|
version: '0'
|
|
113
113
|
requirements: []
|
|
114
|
-
rubygems_version: 3.
|
|
114
|
+
rubygems_version: 3.4.19
|
|
115
115
|
signing_key:
|
|
116
116
|
specification_version: 4
|
|
117
117
|
summary: Ruby class for aligning two character strings
|