Class: FuzzyMatch::Rule::Grouping
- Inherits:
-
FuzzyMatch::Rule
- Object
- FuzzyMatch::Rule
- FuzzyMatch::Rule::Grouping
- Defined in:
- lib/fuzzy_match/rule/grouping.rb
Overview
“Record linkage typically involves two main steps: grouping and scoring…” en.wikipedia.org/wiki/Record_linkage
Groupings effectively divide up the haystack into groups that match a pattern
A grouping (formerly known as a blocking) comes into effect when a str matches. Then the needle must also match the grouping’s regexp.
Instance Attribute Summary collapse
-
#chain ⇒ Object
Returns the value of attribute chain.
Attributes inherited from FuzzyMatch::Rule
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from FuzzyMatch::Rule
Constructor Details
This class inherits a constructor from FuzzyMatch::Rule
Instance Attribute Details
#chain ⇒ Object
Returns the value of attribute chain.
31 32 33 |
# File 'lib/fuzzy_match/rule/grouping.rb', line 31 def chain @chain end |
Class Method Details
.make(regexps) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fuzzy_match/rule/grouping.rb', line 13 def make(regexps) case regexps when ::Regexp new regexps when ::Array chain = regexps.flatten.map { |regexp| new regexp } if chain.length == 1 chain[0] # not really a chain after all else chain.each { |grouping| grouping.chain = chain } chain end else raise ArgumentError, "[fuzzy_match] Groupings should be specified as single regexps or an array of regexps (got #{regexps.inspect})" end end |
Instance Method Details
#inspect ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/fuzzy_match/rule/grouping.rb', line 33 def inspect memo = [] memo << "#{regexp.inspect}" if chain memo << "(#{chain.find_index(self)} of #{chain.length})" end memo.join ' ' end |
#xjoin?(needle, straw) ⇒ Boolean
50 51 52 53 54 55 56 |
# File 'lib/fuzzy_match/rule/grouping.rb', line 50 def xjoin?(needle, straw) if primary? join?(needle, straw) and subs.none? { |sub| sub.match?(straw) } # maybe xmatch here? else join?(needle, straw) and primary.match?(straw) end end |
#xmatch?(record) ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/fuzzy_match/rule/grouping.rb', line 42 def xmatch?(record) if primary? match?(record) and subs.none? { |sub| sub.match?(record) } else match?(record) and primary.match?(record) end end |