Class: Eco::Data::FuzzyMatch::Results
- Includes:
- Enumerable
- Defined in:
- lib/eco/data/fuzzy_match/results.rb
Instance Attribute Summary collapse
-
#needle ⇒ Object
Returns the value of attribute needle.
-
#raw_results ⇒ Object
Returns the value of attribute raw_results.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#merge(res) ⇒ Object
Merges the results of both Results object.
- #order ⇒ Object
- #order=(values) ⇒ Object
- #print ⇒ Object
- #relevant_results(**options) ⇒ Object
- #results ⇒ Object
- #results_with_false_positives ⇒ Object
Instance Attribute Details
#needle ⇒ Object
Returns the value of attribute needle
4 5 6 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 4 def needle @needle end |
#raw_results ⇒ Object
Returns the value of attribute raw_results
4 5 6 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 4 def raw_results @raw_results end |
#threshold ⇒ Object
Returns the value of attribute threshold.
7 8 9 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 7 def threshold @threshold end |
#value ⇒ Object
Returns the value of attribute value
4 5 6 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 4 def value @value end |
Instance Method Details
#each(&block) ⇒ Object
13 14 15 16 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 13 def each(&block) return to_enum(:each) unless block raw_results.each(&block) end |
#empty? ⇒ Boolean
9 10 11 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 9 def empty? count < 1 end |
#merge(res) ⇒ Object
Merges the results of both Results object
19 20 21 22 23 24 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 19 def merge(res) unless self.needle == res.needle raise "To merge 2 Results, needle should be the same ('#{value}'). Given '#{res.value}'" end self.class.new(needle, value, raw_results.concat(res.raw_results)) end |
#order ⇒ Object
49 50 51 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 49 def order @order ||= [:words_ngrams, :dice] end |
#order=(values) ⇒ Object
43 44 45 46 47 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 43 def order=(values) @order = [values].flatten.compact.tap do |o| raw_results.each {|r| r.order = o} end end |
#print ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 57 def print msg = results.map do |result| result.print end.join("\n ") puts "'#{value}':\n " + msg end |
#relevant_results(**options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 30 def relevant_results(**) = {order: order, threshold: threshold || 0.5}.merge() raw_results.select do |result| result.all_threshold?([:order], [:threshold]) end.yield_self do |filtered| self.class.new(needle, value, filtered).tap do |results| results.order = [:order] end end end |
#results ⇒ Object
53 54 55 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 53 def results raw_results.sort end |
#results_with_false_positives ⇒ Object
26 27 28 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 26 def results_with_false_positives relevant_results(order: :jaro_winkler, threshold: 0.5) end |