jaro_winkler 1.1.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f84ae47f4c9a9afe40e7b01c7d49359dd6986009
4
- data.tar.gz: 6994fd05b085d89e203f1c5663915bdc9ce88735
3
+ metadata.gz: 5ca8266cce395bbcf2b425545e7a426110ef2601
4
+ data.tar.gz: 23689730155a05387f5908b4661271f20aa118af
5
5
  SHA512:
6
- metadata.gz: b2bf1f5c392750f82e203aafed8264eaa79750b9a3a11209cc221d8506cbf8b1840cd8822b631f0d5de5c6b8bd2c2c471b0992c55986918b81b9e4ef5236e072
7
- data.tar.gz: c02296f3c27531a518f752177cca86c7e00670a1c3e7566bb6c3b499f7f676148a44fd3ec6848eedd50072bcd94a2c4781d9667440b44cd4032e24570f10a862
6
+ metadata.gz: 67661a5f12b0204e76cf50fc44bad3a912b3a570602d18402e29065a6d75455cf7666b439f1aecb8b4d8f77b380cc5af8ff0b7c1f143b557b6fb4488198c19cf
7
+ data.tar.gz: cb172f54e6ac951d068ad805e157d31c233335e50ecf81c89c15d7cdf50b3b092cbfda044b962639b8e0f48d760bcddfb2277893d70a83b018e63cad97084e0f
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = JaroWinkler::VERSION
9
9
  spec.authors = ["Jian Weihang"]
10
10
  spec.email = ["tonytonyjan@gmail.com"]
11
- spec.extensions = ["ext/jaro_winkler/extconf.rb"]
11
+ spec.extensions = ["ext/jaro_winkler/extconf.rb"] unless RUBY_PLATFORM == 'java'
12
12
  spec.summary = %q{Pure Ruby implementation of Jaro-Winkler distance algorithm.}
13
13
  spec.description = %q{Pure Ruby implementation of Jaro-Winkler distance algorithm.}
14
14
  spec.homepage = "https://github.com/tonytonyjan/jaro_winkler"
@@ -1,15 +1,19 @@
1
- require 'jaro_winkler/jaro_winkler.so'
1
+ require 'jaro_winkler/jaro_winkler.so' unless RUBY_PLATFORM == 'java'
2
2
  module JaroWinkler
3
3
  module_function
4
4
  def jaro_distance s1, s2
5
5
  return 0.0 if s1.empty? || s2.empty?
6
+ # Guarantee the length order
7
+ if s1.length > s2.length
8
+ tmp = s1; s1 = s2; s2 = tmp
9
+ end
6
10
  length1, length2 = s1.length, s2.length
7
- window_size = ([length1, length2].max / 2) - 1
11
+ window_size = (s2.length / 2) - 1
8
12
  matches = 0.0
9
13
  transpositions = 0
10
14
  previous_index = -1
15
+ max_index = length2 - 1
11
16
  s1.chars.each_with_index do |c1, i|
12
- max_index = length2 - 1
13
17
  left = i - window_size
14
18
  right = i + window_size
15
19
  left = 0 if left < 0
@@ -39,7 +43,7 @@ module JaroWinkler
39
43
 
40
44
  def distance s1, s2, options = {}
41
45
  options = {weight: 0.1, threshold: 0.7, case_match: false, native: false}.merge options
42
- return c_distance(s1, s2) if options[:native]
46
+ return c_distance(s1, s2) if RUBY_PLATFORM != 'java' && options[:native]
43
47
  weight, threshold, case_match = options[:weight], options[:threshold], options[:case_match]
44
48
  raise 'Scaling factor should not exceed 0.25, otherwise the distance can become larger than 1' if weight > 0.25
45
49
  s1, s2 = s1.downcase, s2.downcase if case_match
@@ -1,3 +1,3 @@
1
1
  module JaroWinkler
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -15,7 +15,9 @@ describe JaroWinkler do
15
15
  ['tonytonyjan', 'tonytonyjan', 1.0],
16
16
  ['', '', 0.0],
17
17
  ['tony', '', 0.0],
18
- ['', 'tony', 0.0]
18
+ ['', 'tony', 0.0],
19
+ ['tonytonyjan', 'tony', 0.8727],
20
+ ['tony', 'tonytonyjan', 0.8727]
19
21
  ]
20
22
  end
21
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaro_winkler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jian Weihang