-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
184 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
node_modules | ||
.DS_Store | ||
*.log | ||
.nyc_output/ | ||
coverage/ | ||
node_modules/ | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- lts/dubnium | ||
- node | ||
after_script: bash <(curl -s https://codecov.io/bash) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
var distance = require("leven") | ||
'use strict' | ||
|
||
module.exports = function(a,b) { | ||
if (!a || !b || !a.length || !b.length) return 0 | ||
var levenshtein = require('levenshtein-edit-distance') | ||
|
||
module.exports = similarity | ||
|
||
function similarity(a, b) { | ||
if (!a || !b || a.length === 0 || b.length === 0) return 0 | ||
if (a === b) return 1 | ||
var d = distance(a.toLowerCase(),b.toLowerCase()) | ||
var d = levenshtein(a.toLowerCase(), b.toLowerCase()) | ||
var longest = Math.max(a.length, b.length) | ||
return (longest-d)/longest | ||
return (longest - d) / longest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License | ||
|
||
Copyright (c) 2014 Zeke Sikelianos <zeke@sikelianos.com> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# similarity | ||
|
||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
|
||
How similar are these two strings? | ||
|
||
## Install | ||
|
||
[npm][]: | ||
|
||
```sh | ||
npm install similarity | ||
``` | ||
|
||
## Use | ||
|
||
```js | ||
var similarity = require('similarity') | ||
|
||
similarity('food', 'food') // 1 | ||
similarity('food', 'fool') // 0.75 | ||
similarity('ding', 'plow') // 0 | ||
similarity('chicken', 'chick') // 0.714285714 | ||
similarity('es6-shim', 'es6 shim') // 0.875 | ||
similarity('ES6-Shim', 'es6 shim') // 0.875 (case insensitive) | ||
``` | ||
|
||
## See also | ||
|
||
Note: This module uses [Levenshtein distance][wiki] to measure similarity, but | ||
there are many other algorithms for string comparison. | ||
Here are a few: | ||
|
||
* [`clj-fuzzy`](https://github.com/Yomguithereal/clj-fuzzy) | ||
— Handy collection of algorithms dealing with fuzzy strings and phonetics | ||
* [natural](https://github.com/NaturalNode/natural) | ||
— General natural language facilities for node | ||
* [`string-similarity`](https://github.com/aceakash/string-similarity) | ||
— Finds degree of similarity between two strings, based on Dice’s | ||
coefficient | ||
* [`dice-coefficient`](https://github.com/words/dice-coefficient) | ||
— Sørensen–Dice coefficient | ||
* [`jaro-winkler`](https://github.com/jordanthomas/jaro-winkler) | ||
— The Jaro-Winkler distance metric | ||
|
||
## License | ||
|
||
[ISC][license] © [Zeke Sikelianos][author] | ||
|
||
<!-- Definitions --> | ||
|
||
[build-badge]: https://img.shields.io/travis/words/similarity.svg | ||
|
||
[build]: https://travis-ci.org/words/similarity | ||
|
||
[coverage-badge]: https://img.shields.io/codecov/c/github/words/similarity.svg | ||
|
||
[coverage]: https://codecov.io/github/words/similarity | ||
|
||
[downloads-badge]: https://img.shields.io/npm/dm/similarity.svg | ||
|
||
[downloads]: https://www.npmjs.com/package/similarity | ||
|
||
[size-badge]: https://img.shields.io/bundlephobia/minzip/similarity.svg | ||
|
||
[size]: https://bundlephobia.com/result?p=similarity | ||
|
||
[npm]: https://www.npmjs.com | ||
|
||
[license]: license | ||
|
||
[author]: http://zeke.sikelianos.com | ||
|
||
[wiki]: https://en.wikipedia.org/wiki/Levenshtein_distance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var test = require('tape') | ||
var similarity = require('.') | ||
|
||
test('similarity', function(t) { | ||
t.equal(similarity('food', 'food'), 1) | ||
t.equal(similarity('food', 'fool'), 0.75) | ||
t.equal(similarity('ding', 'plow'), 0) | ||
t.equal(similarity('chicken', 'chick'), 5 / 7) | ||
t.equal(similarity('es6-shim', 'es6 shim'), 7 / 8) | ||
t.equal(similarity('ES6 Shim', 'es6-shim'), 7 / 8, 'it’s case insensitive') | ||
t.end() | ||
}) |
This file was deleted.
Oops, something went wrong.