Permalink
Browse files

make it clear that we're converting dice and levenshtein into similar…

…ity values from 0..1
  • Loading branch information...
1 parent b6d2491 commit a7e7cd5f41b53da4b43786f5a7a5c0cb8c0c4a05 @seamusabshere seamusabshere committed Jan 13, 2012
Showing with 11 additions and 11 deletions.
  1. +2 −2 lib/fuzzy_match.rb
  2. +9 −9 lib/fuzzy_match/score.rb
View
@@ -160,11 +160,11 @@ def find(needle, options = {})
return similarities.map { |similarity| similarity.wrapper2.record }
end
- if best_similarity = similarities.first and best_similarity.best_score.dices_coefficient > 0
+ if best_similarity = similarities.first and best_similarity.best_score.dices_coefficient_similar > 0
record = best_similarity.wrapper2.record
if gather_last_result
last_result.record = record
- last_result.score = best_similarity.best_score.dices_coefficient
+ last_result.score = best_similarity.best_score.dices_coefficient_similar
end
record
end
View
@@ -14,13 +14,13 @@ def initialize(str1, str2)
end
def inspect
- %{#<Score: dices_coefficient=#{dices_coefficient} levenshtein=#{levenshtein}>}
+ %{#<Score: dices_coefficient=#{dices_coefficient_similar} levenshtein=#{levenshtein_similar}>}
end
def <=>(other)
- by_dices_coefficient = (dices_coefficient <=> other.dices_coefficient)
+ by_dices_coefficient = (dices_coefficient_similar <=> other.dices_coefficient_similar)
if by_dices_coefficient == 0
- levenshtein <=> other.levenshtein
+ levenshtein_similar <=> other.levenshtein_similar
else
by_dices_coefficient
end
@@ -32,19 +32,19 @@ def utf8?
if defined?(::Amatch)
- def dices_coefficient
+ def dices_coefficient_similar
str1.pair_distance_similar str2
end
- def levenshtein
+ def levenshtein_similar
str1.levenshtein_similar str2
end
else
SPACE = ' '
# http://stackoverflow.com/questions/653157/a-better-similarity-ranking-algorithm-for-variable-length-strings
- def dices_coefficient
+ def dices_coefficient_similar
if str1 == str2
return 1.0
elsif str1.length == 1 and str2.length == 1
@@ -77,7 +77,7 @@ def dices_coefficient
# extracted/adapted from the text gem version 1.0.2
# normalization added for utf-8 strings
# lib/text/levenshtein.rb
- def levenshtein
+ def levenshtein_similar
if utf8?
unpack_rule = 'U*'
else
@@ -118,8 +118,8 @@ def levenshtein
end
extend ::ActiveSupport::Memoizable
- memoize :dices_coefficient
- memoize :levenshtein
+ memoize :dices_coefficient_similar
+ memoize :levenshtein_similar
memoize :utf8?
end
end

0 comments on commit a7e7cd5

Please sign in to comment.