fuzzyset.js

repository·master·Indexed 23 days ago

https://github.com/glench/fuzzyset.js

A fast fuzzy string set for JavaScript designed for approximate string matching and finding likely misspellings. It provides a FuzzySet data structure to add strings and query them using a scoring system based on Levenshtein distance and gram sizes.

Tokens
660
Snippets
2
Records
6
Agent score
30%

What's inside fuzzyset

  1. Initialize FuzzySet with construction arguments

    master

    When creating a new FuzzySet instance, you can pass an options object to configure the matching behavior and initial data.

    Arguments:

    • 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. (Default: 2)
    • gramSizeUpper: The upper bound of gram sizes to use, inclusive. (Default: 3)
  2. Install fuzzyset

    master

    You can install fuzzyset via npm for Node.js or TypeScript projects, or include it directly in a web browser using a <script> tag.

    npm installation

    npm install fuzzyset

    Import in JavaScript/TypeScript

    import FuzzySet from 'fuzzyset'
    
    // or
    
    const FuzzySet = require('fuzzyset')

    Browser usage

    <script type="text/javascript" src="dist/fuzzyset.js"></script>
  3. Perform fuzzy string matching with FuzzySet

    master

    Fuzzyset is a data structure for approximate string matching and finding likely misspellings. You can add strings to a set and then query them using the .get() method.

    When using .get(), the returned results are an array of [score, matched_value] arrays. The score is a float between 0 and 1, where 1 represents a perfect match.

       a = FuzzySet();
       a.add("michael axiak");
       a.get("micael asiak");
       // will be [[0.8461538461538461, 'michael axiak']];
  4. FuzzySet API Reference

    master

    The following methods are available on a FuzzySet instance:

    • get(value, [default], [minScore=.33]): Tries to match a string to entries with a score of at least minScore. If no match is found, it returns null or the provided default value.
    • add(value): Adds a value to the set. Returns false if the value was already present.
    • length(): Returns the number of items currently in the set.
    • isEmpty(): Returns true if the set is empty.
    • values(): Returns an array containing all the values in the set.
  5. Commercial licensing for fuzzyset

    master

    Fuzzyset is licensed under the Prosperity Public License 3.0.

    • Non-commercial projects: Free to use (personal, research, education, public benefit, etc.).
    • Commercial projects: If your project is commercial (including internal use at a company), you must purchase a one-time licensing fee of $42 after a 30-day free trial period.
  6. Use the FuzzySet class

    master
    The fuzzyset package provides the FuzzySet class, which is used to create a fuzzy string set for performing approximate string matching and searching. The main entry point exports the FuzzySet constructor.