0.0
No commit activity in last 3 years
No release in over 3 years
An implementation of the White Similarity Algorithm in C
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

WhiteSimilarity

WhiteSimilarity is a Ruby gem that implements the White String Similarity Algorithm for computing the similarity between two strings. The algorithm was introduced by Simon White here.

For this gem, the actual algorithm is implemented in C and maintained at jfairbank/c_white_algorithm.

Installation

Add this line to your application's Gemfile:

gem 'whitesimilarity'

And then execute:

$ bundle

Or install it yourself as:

$ gem install whitesimilarity

Usage

The only method is WhiteSimilarity.similarity which takes two strings to compare.

WhiteSimilarity.similarity('foo', 'bar')  # 0.0
WhiteSimilarity.similarity('dog', 'doge') # 0.8
WhiteSimilarity.similarity('dog', 'DOGE') # 0.8 - Case insensitive
WhiteSimilarity.similarity('foo', 'for')  # 0.5

A common use case for the similarity algorithm is to find the best matching string for another given string.

class Choices < Array
  def best_match_to(a_string)
    self.sort do |a, b|
      WhiteSimilarity.similarity(a_string, b) <=> WhiteSimilarity.similarity(a_string, a)
    end.first
  end
end

c = Choices.new %w(foo bar quux hello world)

puts c.best_match_to 'help' #=> 'hello'

Contributing

To contribute to the algorithm implementation, please fork jfairbank/c_white_algorithm instead of this repo

  1. Fork jfairbank/c_white_algorithm
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request