GithubHelp home page GithubHelp logo

stollcri / fuzziac.js Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 577 KB

JavaScript class for on-line approximate string matching (for use with auto-complete)

License: MIT License

JavaScript 86.90% HTML 13.10%

fuzziac.js's Introduction

Fuzziac

A utility for on-line approximate string matching

Fuzziac.js is Javascript class for on-line approximate string matching. It was originally intended for use with auto-complete, but it's really just a plain Javascript class, so use it as you see fit.

This is started as a research project for an undergraduate algorithms class which I took way back in 2011. We had to complete a term project on an algorithm, and Dr. Duan made dynamic programming look cool, so I though I would look for an application of dynamic programming outside the realm of DNA sequencing.

If you would like to know the full story on how I came to develop this solution you can read the post I wrote about the history of fuzziac.js, or you can read my original research paper.

Installation

To use fuzziac in your Node app:

npm

npm install --save fuzziac

yarn

yarn add fuzziac

Usage

Calculate the Match Score of Two Strings

const Fuzziac = require('fuzziac');
const fuzziac = new Fuzziac()
fuzziac.score("Joe", "Moe")

Find the Best Matches from an Array

const Fuzziac = require('fuzziac');
const fuzziac = new Fuzziac([
    "Larry",
    "Curly",
    "Moe"
], false)
const searchResults = fuzziac.search("Joe");

Search Sessions

Fuzziac is best when it is used with an automcomplete for a large dataset, but it operates in linear time (something like O(nm)). So, large datasets could mean unacceptably long runtimes. One way to improve performance is to progressively reduce the size of the dataset as subsequent searches are performed. To enable this behavior a session is started after the first string longer than 2 characters is searched for. When the search session is over it must be manually closed. From a practical perspective, when a user is typing into a search box the resulting strings should be passed to Fuzziac, and when the user selects the result they want the Fuzziac search should be closed.

const Fuzziac = require('fuzziac');
const fuzziac = new Fuzziac([
    "Larry",
    "Curly",
    "Moe"
])

let searchResults = [];

// for "J" the entire dataset is searched
searchResults = fuzziac.search("J")
// [ 'Curly', 'Larry' ]

// for "Jo" the entire dataset is searched
searchResults = fuzziac.search("Jo")
// [ 'Moe' ]

// for "Joe" the dataset filtered by "Jo" is searched
searchResults = fuzziac.search("Joe")
// [ 'Moe' ]

fuzziac.closeSearchSession();

// now for "Joe" the entire dataset is searched
searchResults = fuzziac.search("Joe")
// [ 'Moe', 'Curly', 'Larry' ]

fuzziac.js's People

Contributors

stollcri avatar

Stargazers

Amit Nambiar avatar Ted Lee avatar Juan Carlos Saavedra avatar Marc Lundgren avatar evandrix avatar

Watchers

evandrix avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.