Skip to content

Instantly share code, notes, and snippets.

@codatory
Created June 21, 2012 03:32
Show Gist options
  • Select an option

  • Save codatory/2963654 to your computer and use it in GitHub Desktop.

Select an option

Save codatory/2963654 to your computer and use it in GitHub Desktop.
Fuzzy string matching convenience class
require 'fuzzystringmatch'
class Phrase
attr_reader :matches
def initialize(str, match_score=0.8)
@str = str
@matches = []
@match_score = match_score
@scorer = FuzzyStringMatch::JaroWinkler.create
end
def compare(word)
score = @scorer.getDistance(word,@str)
if score > @match_score
@matches << word
return score
end
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment