Class: Eco::Data::FuzzyMatch::Result
- Defined in:
- lib/eco/data/fuzzy_match/result.rb
Constant Summary collapse
- ALL_METHODS =
%i[ dice levenshtein jaro_winkler ngrams words_ngrams chars_position ].freeze
Instance Attribute Summary collapse
-
#chars_position ⇒ Object
Returns the value of attribute chars_position.
-
#dice ⇒ Object
Returns the value of attribute dice.
-
#jaro_winkler ⇒ Object
Returns the value of attribute jaro_winkler.
-
#levenshtein ⇒ Object
Returns the value of attribute levenshtein.
-
#match ⇒ Object
Returns the value of attribute match.
-
#needle_value ⇒ Object
Returns the value of attribute needle_value.
-
#ngrams ⇒ Object
Returns the value of attribute ngrams.
-
#pivot ⇒ Object
Returns the value of attribute pivot.
-
#value ⇒ Object
Returns the value of attribute value.
-
#words_ngrams ⇒ Object
Returns the value of attribute words_ngrams.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #all_threshold?(methods = order, threshold = 0.15) ⇒ Boolean
- #any_threshold?(methods = order, threshold = 0.15) ⇒ Boolean
- #average ⇒ Object
- #jaro ⇒ Object
-
#lev ⇒ Object
Shortcuts.
- #order ⇒ Object
- #order=(values) ⇒ Object
- #pos ⇒ Object
-
#print ⇒ Object
TODO: print in the order of
order. - #threshold?(method = :dice, threshold = 0.15) ⇒ Boolean
- #values_at(*keys) ⇒ Object
- #wngrams ⇒ Object
Instance Attribute Details
#chars_position ⇒ Object
Returns the value of attribute chars_position
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def chars_position @chars_position end |
#dice ⇒ Object
Returns the value of attribute dice
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def dice @dice end |
#jaro_winkler ⇒ Object
Returns the value of attribute jaro_winkler
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def jaro_winkler @jaro_winkler end |
#levenshtein ⇒ Object
Returns the value of attribute levenshtein
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def levenshtein @levenshtein end |
#match ⇒ Object
Returns the value of attribute match
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def match @match end |
#needle_value ⇒ Object
Returns the value of attribute needle_value
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def needle_value @needle_value end |
#ngrams ⇒ Object
Returns the value of attribute ngrams
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def ngrams @ngrams end |
#pivot ⇒ Object
Returns the value of attribute pivot.
20 21 22 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 20 def pivot @pivot end |
#value ⇒ Object
Returns the value of attribute value
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def value @value end |
#words_ngrams ⇒ Object
Returns the value of attribute words_ngrams
4 5 6 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 4 def words_ngrams @words_ngrams end |
Instance Method Details
#<=>(other) ⇒ Object
106 107 108 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 106 def <=>(other) compare(other) end |
#all_threshold?(methods = order, threshold = 0.15) ⇒ Boolean
78 79 80 81 82 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 78 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) ⇒ Boolean
84 85 86 87 88 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 84 def any_threshold?(methods = order, threshold = 0.15) return true unless threshold [methods].flatten.compact.any? {|method| threshold?(method, threshold)} end |
#average ⇒ Object
63 64 65 66 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 63 def average values = [dice, levenshtein, jaro_winkler, ngrams, words_ngrams, chars_position] (values.inject(0.0, :+) / values.length).round(3) end |
#jaro ⇒ Object
51 52 53 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 51 def jaro jaro_winkler end |
#lev ⇒ Object
Shortcuts
47 48 49 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 47 def lev levenshtein end |
#order ⇒ Object
102 103 104 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 102 def order @order ||= %i[words_ngrams dice] end |
#order=(values) ⇒ Object
96 97 98 99 100 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 96 def order=(values) @order = [values].flatten.compact.tap do |o| o << %i[words_ngrams dice] if o.empty? end end |
#pos ⇒ Object
59 60 61 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 59 def pos chars_position end |
#print ⇒ Object
TODO: print in the order of order
69 70 71 72 73 74 75 76 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 69 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) ⇒ Boolean
90 91 92 93 94 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 90 def threshold?(method = :dice, threshold = 0.15) raise ArgumentError, "Uknown method '#{method}'" unless respond_to?(method, true) send(method) >= threshold end |
#values_at(*keys) ⇒ Object
110 111 112 113 114 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 110 def values_at(*keys) keys.map do |key| send(key) if respond_to?(key) end end |
#wngrams ⇒ Object
55 56 57 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 55 def wngrams words_ngrams end |