- What is this?
- When should I use this?
- Install
- Use
- API
- CLI
- Types
- Compatibility
- Related
- Contribute
- Security
- License
This package exposes a string similarity algorithm.
That means it gets two strings (typically words), and turns it into a number
between 0
(completely different) and 1
(exactly the same).
You’re probably dealing with natural language, and know you need this, if you’re here!
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
npm install dice-coefficient
In Deno with esm.sh
:
import {diceCoefficient} from 'https://esm.sh/dice-coefficient@2'
In browsers with esm.sh
:
<script type="module">
import {diceCoefficient} from 'https://esm.sh/dice-coefficient@2?bundle'
</script>
import {diceCoefficient} from 'dice-coefficient'
diceCoefficient('abc', 'abc') // => 1
diceCoefficient('abc', 'xyz') // => 0
diceCoefficient('night', 'nacht') // => 0.25
diceCoefficient('night', 'nacht') === dice('NiGhT', 'NACHT') // => true
This package exports the identifier diceCoefficient
.
There is no default export.
Get the difference according to Sørensen–Dice.
👉 Note: you can pass bigrams (from
n-gram
) too, which will improve performance when you are comparing the same values multiple times.
Primary value (string
, Array<String>
, required).
Other value (string
, Array<String>
, required).
Difference (number
).
The result is normalized to a number between 0
(completely different)
and 1
(exactly the same).
Usage: dice-coefficient [options] <word> <word>
Sørensen–Dice coefficient
Options:
-h, --help output usage information
-v, --version output version number
Usage:
# output edit distance
$ dice-coefficient night nacht
# 0.25
# output edit distance from stdin
$ echo "saturday sunday" | dice-coefficient
# 0.3333333333333333
This package is fully typed with TypeScript. It exports no additional types.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
levenshtein-edit-distance
— levenshtein edit distancelancaster-stemmer
— lancaster stemming algorithmdouble-metaphone
— double metaphone algorithmsoundex-code
— soundex algorithmsyllable
— syllable count of English words
Yes please! See How to Contribute to Open Source.
This package is safe.