wolf_core 1.1.27 → 1.1.28
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/lib/wolf_core/utils/string_utils.rb +65 -0
- data/lib/wolf_core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91b0f1648e9860c15214dc810166b4588c72b4ca4db3bb2f277d70b45b1340de
|
|
4
|
+
data.tar.gz: df8d5a91a1be6af9e333639cbedb60ac760c6872a814b915c26847f5151ce466
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f41961527ded090fe4bf7338f90a77294bfe2b1556613bd2565682edab5cc27c47361cf5daf080cf35a02ecb88710b0bd4775c027d5a2643c3ccbef3ffaa856
|
|
7
|
+
data.tar.gz: b253298cd99e4ffcece5f536e7117e25c5397d7570c827211f71161bf5d95d27594f2e4d5989556f0433724371961b2a0b2026a602e0ca41e112a1b7f882cf98
|
|
@@ -145,5 +145,70 @@ module WolfCore
|
|
|
145
145
|
{ first_name: name, last_name: lastname }
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
def jaro_winkler_similarity(string1, string2)
|
|
149
|
+
str1 = string1.to_s.strip.downcase
|
|
150
|
+
str2 = string2.to_s.strip.downcase
|
|
151
|
+
|
|
152
|
+
return 1.0 if str1 == str2
|
|
153
|
+
return 0.0 if str1.empty? || str2.empty?
|
|
154
|
+
|
|
155
|
+
max_len = [str1.length, str2.length].max
|
|
156
|
+
match_distance = [(max_len / 2) - 1, 0].max
|
|
157
|
+
|
|
158
|
+
str1_matches = Array.new(str1.length, false)
|
|
159
|
+
str2_matches = Array.new(str2.length, false)
|
|
160
|
+
|
|
161
|
+
matches = 0
|
|
162
|
+
|
|
163
|
+
str1.each_char.with_index do |char, i|
|
|
164
|
+
start = [i - match_distance, 0].max
|
|
165
|
+
finish = [i + match_distance + 1, str2.length].min
|
|
166
|
+
|
|
167
|
+
(start...finish).each do |j|
|
|
168
|
+
next if str2_matches[j]
|
|
169
|
+
next unless str2[j] == char
|
|
170
|
+
|
|
171
|
+
str1_matches[i] = true
|
|
172
|
+
str2_matches[j] = true
|
|
173
|
+
matches += 1
|
|
174
|
+
break
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
return 0.0 if matches.zero?
|
|
179
|
+
|
|
180
|
+
transpositions = 0
|
|
181
|
+
j = 0
|
|
182
|
+
|
|
183
|
+
str1.each_char.with_index do |char, i|
|
|
184
|
+
next unless str1_matches[i]
|
|
185
|
+
|
|
186
|
+
j += 1 while j < str2.length && !str2_matches[j]
|
|
187
|
+
break if j >= str2.length
|
|
188
|
+
|
|
189
|
+
transpositions += 1 if str2[j] != char
|
|
190
|
+
j += 1
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
transpositions /= 2.0
|
|
194
|
+
|
|
195
|
+
jaro = (
|
|
196
|
+
(matches / str1.length.to_f) +
|
|
197
|
+
(matches / str2.length.to_f) +
|
|
198
|
+
((matches - transpositions) / matches)
|
|
199
|
+
) / 3.0
|
|
200
|
+
|
|
201
|
+
prefix_length = 0
|
|
202
|
+
max_prefix = 4
|
|
203
|
+
while prefix_length < max_prefix &&
|
|
204
|
+
prefix_length < str1.length &&
|
|
205
|
+
prefix_length < str2.length &&
|
|
206
|
+
str1[prefix_length] == str2[prefix_length]
|
|
207
|
+
prefix_length += 1
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
jaro + (prefix_length * 0.1 * (1 - jaro))
|
|
211
|
+
end
|
|
212
|
+
|
|
148
213
|
end
|
|
149
214
|
end
|
data/lib/wolf_core/version.rb
CHANGED