fuzzyset.js

A fuzzy string set for javascript. A data structure that performs something akin to fulltext search against data to determine likely mispellings and approximate string matching. Scroll down for an interactive example.

View and Download on Github »

Usage

a = FuzzySet(['Michael Axiak']);
a.get("micael asiak");
[[0.8461538461538461, 'Michael Axiak']]

Install

<script src="fuzzyset.js"></script>

or

npm install fuzzyset.js

Try it out

Open up your console and try it out! f = FuzzySet(['what'])

Also check out the python version.


Constructor Arguments

Arguments to constructor function FuzzySet().

Argument Description
array An array of strings to initialize the data structure with
useLevenshtein Whether or not to use the levenshtein distance to determine the match scoring. Default: True
gramSizeLower The lower bound of gram sizes to use, inclusive (see Theory of operation). Default: 2
gramSizeUpper The upper bound of gram sizes to use, inclusive (see Theory of operation). Default: 3

Methods

Methods on initialized FuzzySet object.

Method Description
get(value, [default], [minScore]) try to match a string to entries, otherwise return null or default if it is given. You can provide an optional score between 0 and 1 that results must be greater than.
add(value) add a value to the set returning false if it is already in the set.
length() return the number of items in the set.
isEmpty() returns true if the set is empty.
values() returns an array of the values in the set.