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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14d1de369f68ca4e81ccf8fbb56b3d61f867013950b1aad20344024274f554fc
4
- data.tar.gz: f53a29864e22c779f0d14f63961b599e799f34656303d976346882a56a025fb8
3
+ metadata.gz: 91b0f1648e9860c15214dc810166b4588c72b4ca4db3bb2f277d70b45b1340de
4
+ data.tar.gz: df8d5a91a1be6af9e333639cbedb60ac760c6872a814b915c26847f5151ce466
5
5
  SHA512:
6
- metadata.gz: 8b62c2b3ffc46d695ed952602cebd794533e6568e0cb329e6cd1b7bac781058dc82bfc8628e3b3a9e5016be115f90c44ed31b1f9b80d75bec7ff1e737e153a36
7
- data.tar.gz: 0264a99d1c8f247d75f183fb209c953dbec2b68642beb19625af74dc7e04c135802150b8bdcbb0846b066a2bc080fe95ef74b2911414ceea3cf400e197d4d06f
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.1.27"
4
+ VERSION = "1.1.28"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.27
4
+ version: 1.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo