Git Product home page Git Product logo

how-similar's Introduction

How Similar

This module compares two strings and returns a value on how similar they are from 0 - 1 (using a normalized levenshtein distance). The most basic use is:

> const {similarity} = require('how-similar')
> similarity('Dublin', 'Doblin')
0.833

The module can also compare a string to an array of strings to find which one is the most similar one:

> similarity('Dublin', ['Doblin', 'Devlin', 'Duuublin', 'Dublin'])
[ { key: 'Dublin', value: 1 },
  { key: 'Doblin', value: 0.875 },
  { key: 'Devlin', value: 0.75 },
  { key: 'Duuublin', value: 0.75 } ]

Install

You can install with [npm]:

$ npm install --save how-similar

Usage

The module provides functions to deal with string / string comparison and string / array comparison. Still the easiest way to use it is to import similarity:

> const {similarity} = require('how-similar')

Then as shown above you can pass two strings or an string and an array of strings. You can also pass a third parameter with options (it will be explained next).

Examples

The following use cases can be solved with the module:

  1. How similar are two different strings:
> similarity('Dublin', 'Doblin')
0.833
  1. What is the most similar string in an array to another string:
> similarity('Dublin', ['Doblin', 'Devlin', 'Duuublin', 'Dublin'])
[ { key: 'Dublin', value: 1 },
  { key: 'Doblin', value: 0.875 },
...
  1. How similar ignoring the case ({ignorecase: true}):
> similarity('Dublin', 'dUblIn', {ignorecase: true})
1
  1. How similar stemming the words ({stem: true}):
> similarity('This is Dublin', 'Thi is Dublin', {stem: true})
1
  1. How similar with exceptions ({except: [word1, word2, ...]})
> similarity('This is Dublin in Ireland', 'This is Dublin', {except: ['in', 'Ireland']})
1

License

Copyright © 2019, Juan Convers. Released under the MIT License.

how-similar's People

Watchers

James Cloos avatar Juan Convers avatar

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.