Sha256: eac5f84d1fa40375b82989ff7f1296e269bb6a3ca1550a019b2e1df61653dd62

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

class FuzzyMatch
  class Rule
    # "Record linkage typically involves two main steps: grouping and scoring..."
    # http://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.
    class Grouping < Rule
      def match?(str)
        !!(regexp.match(str))
      end

      # If a grouping "joins" two strings, that means they both fit into it.
      #
      # Returns false if they certainly don't fit this grouping.
      # Returns nil if the grouping doesn't apply, i.e. str2 doesn't fit the grouping.
      def join?(str1, str2)
        if str2_match_data = regexp.match(str2)
          if str1_match_data = regexp.match(str1)
            str2_match_data.captures.join.downcase == str1_match_data.captures.join.downcase
          else
            false
          end
        else
          nil
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fuzzy_match-1.5.0 lib/fuzzy_match/rule/grouping.rb
fuzzy_match-1.4.1 lib/fuzzy_match/rule/grouping.rb
fuzzy_match-1.4.0 lib/fuzzy_match/rule/grouping.rb
fuzzy_match-1.3.3 lib/fuzzy_match/rule/grouping.rb
fuzzy_match-1.3.2 lib/fuzzy_match/rule/grouping.rb