fuzzy_string 0.0.2 → 0.0.2.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/lib/fuzzy_string/adjusted_score.rb +3 -1
- data/lib/fuzzy_string/version.rb +1 -1
- data/test/fuzzy_string_test.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a34cf02fb947f066a762738cac66355bf2cc99
|
4
|
+
data.tar.gz: a2d2c08aef3e4b5050e4a7424b9576467064497a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1316195174c23eb0cc380d3fe26caa637ef22a5a190cb036a06742fa820bf7f284073420bb8f0826197fb736cbbee502f75e53c4b8b39ac1e660d35ad5da911
|
7
|
+
data.tar.gz: ca346b8a5bb3e834e643a395aead1cd65382d89a6dafcf0a6e3e224a956bbf1bbdaab252bce0cfc0a5d4e04a2fdc547670201154a476696f84e19938e84263f8
|
@@ -13,9 +13,11 @@ class FuzzyString::AdjustedScore
|
|
13
13
|
def adjusted_levenschtein_distance
|
14
14
|
pieces = @first.split(/#{@second.chars.to_a.join('(.*?)')}/i)
|
15
15
|
score = pieces[0][-1] == ' ' ? -1 : 0
|
16
|
+
score += pieces[0..@second.length - 1].uniq == [''] ? -@first.length.to_f / 2 : 0
|
17
|
+
score += (pieces[@second.length] || [])[0] == ' ' ? -@first.length.to_f / 2 : 0
|
16
18
|
score += cost(pieces.shift,0.5) + cost(pieces.pop,0.25) + cost(pieces.join,1)
|
17
19
|
score += FuzzyString::Levenshtein.distance(@first,@second)
|
18
20
|
end
|
19
21
|
private
|
20
22
|
def cost(piece,multiplier) piece.length * multiplier rescue(0) end
|
21
|
-
end
|
23
|
+
end
|
data/lib/fuzzy_string/version.rb
CHANGED
data/test/fuzzy_string_test.rb
CHANGED
@@ -33,4 +33,11 @@ class FuzzyStringTest < MiniTest::Unit::TestCase
|
|
33
33
|
assert 'ZZmonaZ'^'mona' < 'ZZMonaZ'^'mona'
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_prioritizes_string_starting_with_exact_match
|
37
|
+
assert 'escreen are where I am at' ^ 'escreen' < 'escreens are' ^ 'escreen'
|
38
|
+
end
|
39
|
+
def test_prioritizes_string_starting_with_match
|
40
|
+
assert 'escreens are' ^ 'escreen' < 'I am a n escreen' ^ 'escreen'
|
41
|
+
end
|
42
|
+
|
36
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuzzy_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
4
|
+
version: 0.0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.2.1
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Relative ranking system for strings.
|