class Eco::Data::FuzzyMatch::Result
Constants
- ALL_METHODS
Attributes
pivot[RW]
Public Instance Methods
<=>(result)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 62 def <=>(result) compare(result) end
all_threshold?(methods = order, threshold = 0.15)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 37 def all_threshold?(methods = order, threshold = 0.15) return true unless threshold [methods].flatten.compact.all? {|method| threshold?(method, threshold)} end
any_threshold?(methods = order, threshold = 0.15)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 42 def any_threshold?(methods = order, threshold = 0.15) return true unless threshold [methods].flatten.compact.any? {|method| threshold?(method, threshold)} end
average()
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 22 def average values = [dice, levenshtein, jaro_winkler, ngrams, words_ngrams, chars_position] (values.inject(0.0, :+) / values.length).round(3) end
chars_position()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 14 def chars_position; super&.round(3); end
dice()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 9 def dice; super&.round(3); end
jaro()
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 18 def jaro; jaro_winkler; end
jaro_winkler()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 11 def jaro_winkler; super&.round(3); end
lev()
click to toggle source
Shortcuts
# File lib/eco/data/fuzzy_match/result.rb, line 17 def lev; levenshtein; end
levenshtein()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 10 def levenshtein; super&.round(3); end
ngrams()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 12 def ngrams; super&.round(3); end
order()
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 58 def order @order ||= [:words_ngrams, :dice] end
order=(values)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 52 def order=(values) @order = [values].flatten.compact.tap do |o| o << [:words_ngrams, :dice] if o.empty? end end
pos()
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 20 def pos; chars_position; end
print()
click to toggle source
TODO: print in the order of `order`
# File lib/eco/data/fuzzy_match/result.rb, line 28 def print msg = "(Dice: #{dice}) (Lev Dst: #{levenshtein}) " msg << "(Jaro: #{jaro_winkler}) " msg << "(Ngram: #{ngrams}) (WNgrams: #{words_ngrams}) " msg << "(C Pos: #{chars_position}) " msg << "(Avg: #{average}) " msg << "'#{value}'" end
threshold?(method = :dice, threshold = 0.15)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 47 def threshold?(method = :dice, threshold = 0.15) raise "Uknown method '#{method}'" unless self.respond_to?(method) self.send(method) >= threshold end
values_at(*keys)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 66 def values_at(*keys) keys.map do |key| self.send(key) if self.respond_to?(key) end end
wngrams()
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 19 def wngrams; words_ngrams; end
words_ngrams()
click to toggle source
Calls superclass method
# File lib/eco/data/fuzzy_match/result.rb, line 13 def words_ngrams; super&.round(3); end
Private Instance Methods
compare(other, order: self.order)
click to toggle source
# File lib/eco/data/fuzzy_match/result.rb, line 74 def compare(other, order: self.order) return 0 unless method = order.first raise "Uknown method '#{method}'" unless self.respond_to?(method) && other.respond_to?(method) return -1 if self.send(method) > other.send(method) return 1 if self.send(method) < other.send(method) compare(other, order: order[1..-1]) end