JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20364
  • Score
    100M100P100Q217659F
  • License MIT

Sørensen–Dice coefficient

Package Exports

  • dice-coefficient

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dice-coefficient) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dice-coefficient

Build Coverage Downloads Size

Sørensen–Dice coefficient.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install dice-coefficient

API

This package exports the following identifiers: diceCoefficient. There is no default export.

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

Instead of strings you can also pass lists of bigrams. This can improve performance when processing the same strings repeatedly.

diceCoefficient(['ab', 'bc'], ['xy', 'yz']) // => 0
diceCoefficient(['ab', 'bc'], ['ab', 'bc']) // => 1
diceCoefficient(['ab', 'bc'], ['AB', 'BC']) // => 1

See n-gram for generating bigrams.

import {bigram} from 'n-gram'

const abc = bigram('abc') // => ['ab', 'bc']
const xyz = bigram('xyz') // => ['xy', 'yz']

diceCoefficient(abc, xyz) // => 0

CLI

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

License

MIT © Titus Wormer