string-comparison
JavaScript implementation of tdebatty/java-string-similarity
A library implementing different string similarity, distance and sortMatch measures. A dozen of algorithms (including Levenshtein edit distance and sibblings, Jaro-Winkler, Longest Common Subsequence, cosine similarity etc.) are currently implemented. Check the summary table below for the complete list...
Download & Usage
download
npm install string-comparision --save
yarn add string-comparision
usage
let stringComparision = require('string-comparision')
const Thanos = 'healed'
const Rival = 'sealed'
const Avengers = ['edward', 'sealed', 'theatre']
use by Consine
let cos = stringComparision.consine
console.log(cos.similarity(Thanos, Rival))
console.log(cos.distance(Thanos, Rival))
console.log(cos.sortMatch(Thanos, Avengers))
OverViews
The main characteristics of each implemented algorithm are presented below. The "cost" column gives an estimation of the computational cost to compute the similarity between two strings of length m and n respectively.
API
similarity
.distance
.sortMatch
similarity
Implementing algorithms define a similarity between strings
Params
- thanos [String]
- rival [String]
Return
Return a similarity between 0.0 and 1.0
distance
Implementing algorithms define a distance between strings (0 means strings are identical)
Params
- thanos [String]
- rival [String]
Return
Return a number
sortMatch
介绍
Params
- thanos [String]
- avengers [...String]
Return
Return an array of objects. ex:
[
{ member: 'edward', rating: 0.16666666666666663 },
{ member: 'theatre', rating: 0.4285714285714286 },
{ member: 'mailed', rating: 0.5 },
{ member: 'sealed', rating: 0.8333333333333334 }
]
Release Notes
1.0 version
- Basic building
- Cosine
- DiceCoefficient
- JaccardIndex
- Levenshtein
- LongestCommonSubsequence
- MetricLCS
2.0 version
MIT
MIT