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.
To use fuzziac in your Node app:
npm install --save fuzziac
yarn add fuzziac
const Fuzziac = require('fuzziac');
const fuzziac = new Fuzziac()
fuzziac.score("Joe", "Moe")
const Fuzziac = require('fuzziac');
const fuzziac = new Fuzziac([
"Larry",
"Curly",
"Moe"
], false)
const searchResults = fuzziac.search("Joe");
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' ]