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 17 |
# 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
20 21 22 23 24 25 26 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 20 def merge(res) unless 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
52 53 54 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 52 def order @order ||= %i[words_ngrams dice] end |
#order=(values) ⇒ Object
46 47 48 49 50 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 46 def order=(values) @order = [values].flatten.compact.tap do |o| raw_results.each {|r| r.order = o} end end |
#print ⇒ Object
60 61 62 63 64 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 60 def print msg = results.map(&:print).join("\n ") puts "'#{value}':\n " + msg end |
#relevant_results(**options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 32 def relevant_results(**) = {order: order, threshold: threshold || 0.5}.merge() raw_results.select do |result| result.all_threshold?([:order], [:threshold]) end.then do |filtered| self.class.new(needle, value, filtered).tap do |results| results.order = [:order] end end end |
#results ⇒ Object
56 57 58 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 56 def results raw_results.sort end |
#results_with_false_positives ⇒ Object
28 29 30 |
# File 'lib/eco/data/fuzzy_match/results.rb', line 28 def results_with_false_positives relevant_results(order: :jaro_winkler, threshold: 0.5) end |