Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mhutter/string-similarity
Calculate String Similarities
https://github.com/mhutter/string-similarity
Last synced: 2 days ago
JSON representation
Calculate String Similarities
- Host: GitHub
- URL: https://github.com/mhutter/string-similarity
- Owner: mhutter
- License: mit
- Created: 2015-09-03T22:58:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-17T14:56:38.000Z (almost 5 years ago)
- Last Synced: 2024-12-14T10:40:57.398Z (12 days ago)
- Language: Ruby
- Homepage:
- Size: 43 KB
- Stars: 90
- Watchers: 5
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# String::Similarity
[![Gem Version](https://badge.fury.io/rb/string-similarity.svg)](http://badge.fury.io/rb/string-similarity)
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://rubydoc.org/gems/string-similarity/frames)
[![Build Status](https://travis-ci.org/mhutter/string-similarity.svg)](https://travis-ci.org/mhutter/string-similarity)
[![Code Climate](https://codeclimate.com/github/mhutter/string-similarity/badges/gpa.svg)](https://codeclimate.com/github/mhutter/string-similarity)
[![Test Coverage](https://codeclimate.com/github/mhutter/string-similarity/badges/coverage.svg)](https://codeclimate.com/github/mhutter/string-similarity/coverage)Library for calculating the similarity of two strings.
## State
- [x] Cosine
- [ ] Hamming
- [x] Levenshtein## Installation
Add this line to your application's Gemfile:
```ruby
gem 'string-similarity'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install string-similarity
## Usage
```ruby
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](http://ruby-doc.org/core-2.3.0/doc/syntax/refinements_rdoc.html) to add the functionality to the `String` class:
```ruby
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](http://www.rubytapas.com/episodes/250-Refinements) 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](http://semver.org/).
## 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 RequestBug 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](http://opensource.org/licenses/MIT).