Class: Eco::Data::FuzzyMatch::Result

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#chars_positionObject

Returns the value of attribute chars_position

Returns:

  • (Object)

    the current value of chars_position



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def chars_position
  @chars_position
end

#diceObject

Returns the value of attribute dice

Returns:

  • (Object)

    the current value of dice



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def dice
  @dice
end

#jaro_winklerObject

Returns the value of attribute jaro_winkler

Returns:

  • (Object)

    the current value of jaro_winkler



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def jaro_winkler
  @jaro_winkler
end

#levenshteinObject

Returns the value of attribute levenshtein

Returns:

  • (Object)

    the current value of levenshtein



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def levenshtein
  @levenshtein
end

#matchObject

Returns the value of attribute match

Returns:

  • (Object)

    the current value of match



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def match
  @match
end

#needle_valueObject

Returns the value of attribute needle_value

Returns:

  • (Object)

    the current value of needle_value



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def needle_value
  @needle_value
end

#ngramsObject

Returns the value of attribute ngrams

Returns:

  • (Object)

    the current value of ngrams



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def ngrams
  @ngrams
end

#pivotObject

Returns the value of attribute pivot.



7
8
9
# File 'lib/eco/data/fuzzy_match/result.rb', line 7

def pivot
  @pivot
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



4
5
6
# File 'lib/eco/data/fuzzy_match/result.rb', line 4

def value
  @value
end

#words_ngramsObject

Returns the value of attribute words_ngrams

Returns:

  • (Object)

    the current value of 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

Returns:

  • (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

Returns:

  • (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

#averageObject



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

#jaroObject



18
# File 'lib/eco/data/fuzzy_match/result.rb', line 18

def jaro; jaro_winkler; end

#levObject

Shortcuts



17
# File 'lib/eco/data/fuzzy_match/result.rb', line 17

def lev; levenshtein; end

#orderObject



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

#posObject



20
# File 'lib/eco/data/fuzzy_match/result.rb', line 20

def pos; chars_position; end

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

Returns:

  • (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

#wngramsObject



19
# File 'lib/eco/data/fuzzy_match/result.rb', line 19

def wngrams; words_ngrams; end