Giter Site home page Giter Site logo

string-similarity's Introduction

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.

string-similarity's People

Contributors

imustafin avatar mhutter avatar renovate-bot avatar wppurking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

string-similarity's Issues

Wrong cosine similarity for urls

Not sure if this gem is still maintained, but the returned cosine similarity for the following two urls is 97%

https://maduradas.com/pena-ajena-la-ridicula-actuacion-estos-gaiteros-chavistas-programa-diosdado-video/

https://maduradas.com/sepalo-ortega-diaz-afirmo-globovision-la-vitalicia-deberan-subastadas-al-restituirse-la-democracia/

Even by looking at the urls you can tell they're far from being the same.

Looking at this online tool https://asecuritysite.com/forensics/simstring, the cosine similarity should be 0

Meanwhile, I'm looking at the underlying algorithm.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

bundler
Gemfile

  • Check this box to trigger a request for Renovate to run again on this repository

High similarity result

Hi, I am getting a suspiciously high similarity value for these strings:

3:Númenor Aragorn The Shire usher1b
4:Rivendell Elrond Mordor usher2
5:mordor Sauron mordor usher1a
7:Minas Tirith Faramir Lorien usher1B
8:Lorien Haldir minas tirith usher2B
2:The Shire Bilbo The Shire Usher2A
3:Númenor Aragorn The Shire usher1b
4:Rivendell Elrond Mordor usher2
5:mordor Sauron mordor usher1a
7:Minas Tirith Faramir Lorien usher1B
8:Lorien Haldir minas tirith usher2B

the cosine similarity is 0.991, although a whole line is missing from the first string, is this really the expected result?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.