StringSimilarity provides a very simple api to compare two strings and return a percentage similarity. It is based on the Sørensen–Dice coefficient (https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient)
Add this line to your application's Gemfile:
gem 'string_similarity'
And then execute:
$ bundle
Or install it yourself as:
$ gem install string_similarity
StringSimilarity has two methods, bigram_score
and ngram_score
.
bigram_score
is most useful for strings that do not have spaces in them, e.g. Japanese or Simplified Chinese text.
ngram_score
is most useful for all other languages.
string_1 = 'Translation company in Boulder'
string_2 = 'Translation company in New York'
StringSimilarity.bigram_score(string_1, string_2)
#=> 73
StringSimilarity.ngram_score(string_1, string_2)
#=> 74
- Fork it ( https://github.com/[my-github-username]/string_similarity/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request