text_alignment 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/text_alignment/char_mapping.rb +21 -2
- data/lib/text_alignment/version.rb +1 -1
- metadata +2 -2
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
|
@@ -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] || raise(ArgumentError, "Unusual 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] || raise(ArgumentError, "Unusual 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.12.
|
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: 2023-12-
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-dictionary
|