No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
== Description This gem provides some methods for calculating similarities of two strings. === Currently implemented - Cosine similarity - Levenshtein distance/similarity === Planned - Hamming similarity
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
>= 0
~> 13.0
>= 0
 Project Readme

String::Similarity

Gem Version Documentation Build Status Code Climate Test Coverage

Library for calculating the similarity of two strings.

State

  • Cosine
  • Hamming
  • Levenshtein

Installation

Add this line to your application's Gemfile:

gem 'string-similarity'

And then execute:

$ bundle

Or install it yourself as:

$ gem install string-similarity

Usage

require 'string/similarity'

# Call the methods on the module
String::Similarity.cosine 'foo', 'bar'
# => 0.0
String::Similarity.cosine 'mine', 'thyne'
# => 0.4472135954999579
String::Similarity.cosine 'foo', 'foo'
# => 1.0


# Same for Levenshtein:
String::Similarity.levenshtein_distance('kitten', 'sitting') # or ...
# => 3
String::Similarity.levenshtein('foo', 'far') # or ...
# => 0.5

If you want, you can use Refinements to add the functionality to the String class:

using String::SimilarityRefinements

'string'.cosine_similarity_to 'strong'
# => 0.8333333333333335

'kitten'.levenshtein_distance_to('sitting')
# => 3

'far'.levenshtein_similarity_to('foo')
# => 0.5

(See this free Ruby Tapas Episode if you don't know Refinements)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

This Project uses Semantic Versioning.

Contributing

  1. Fork it ( https://github.com/mhutter/string-similarity/fork )
  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 a new Pull Request

Bug reports and pull requests are welcome on GitHub at https://github.com/mhutter/string-similarity.

License

The gem is available as open source under the terms of the MIT License.