Ruby compare two strings similarity percentage

前端 未结 3 1531
醉酒成梦
醉酒成梦 2020-12-31 09:05

Id like to compare two strings in Ruby and find their similarity

I\'ve had a look at the Levenshtein gem but it seems this was last updated in 2008 and

3条回答
  •  攒了一身酷
    2020-12-31 09:54

    I can recommend the fuzzy-string-match gem.

    You can use it like this (taken from the docs):

    require "fuzzystringmatch"
    jarow = FuzzyStringMatch::JaroWinkler.create(:native)
    p jarow.getDistance("jones", "johnson")
    

    It will return a score ~0.832 which tells how good those strings match.

提交回复
热议问题