Class: Eco::Data::FuzzyMatch::Result
- Defined in:
- lib/eco/data/fuzzy_match/result.rb
Constant Summary collapse
- ALL_METHODS =
[:dice, :levenshtein, :jaro_winkler, :ngrams, :words_ngrams, :chars_position]
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
- #<=>(result) ⇒ 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.
7 8 9 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 7 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
#<=>(result) ⇒ Object
62 63 64 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 62 def <=>(result) compare(result) end |
#all_threshold?(methods = order, threshold = 0.15) ⇒ Boolean
37 38 39 40 |
# 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) ⇒ Boolean
42 43 44 45 |
# 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 ⇒ Object
22 23 24 25 |
# 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 |
#jaro ⇒ Object
18 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 18 def jaro; jaro_winkler; end |
#lev ⇒ Object
Shortcuts
17 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 17 def lev; levenshtein; end |
#order ⇒ Object
58 59 60 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 58 def order @order ||= [:words_ngrams, :dice] end |
#order=(values) ⇒ Object
52 53 54 55 56 |
# 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 ⇒ Object
20 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 20 def pos; chars_position; end |
#print ⇒ Object
TODO: print in the order of order
28 29 30 31 32 33 34 35 |
# 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) ⇒ Boolean
47 48 49 50 |
# 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) ⇒ Object
66 67 68 69 70 |
# 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 ⇒ Object
19 |
# File 'lib/eco/data/fuzzy_match/result.rb', line 19 def wngrams; words_ngrams; end |