0.0.5 • Published 11 years ago

fuzzy-spell-correction v0.0.5

Weekly downloads
1
License
-
Repository
-
Last release
11 years ago

fuzzy spell correction library based on redis database and Dice's coefficient

fuzzy-spell-correction

you need to install redis database first

usage

start redis

$redis-server

create fill.js

var	corrector = require ('fuzzy-spell-correction'),
		redis = require ('redis'),
		db = redis.createClient ();

corrector.db = db;

corrector.add ('we where promised jetpacks™');

create usage.js

var	corrector = require ('fuzzy-spell-correction'),
		redis = require ('redis'),
		db = redis.createClient ();
		
corrector.db = db;

corrector ('we were promized jetpaks', function (err, phrase) {
	console.log (phrase); // -> ['we where promised jetpacks™']
});

you cannot run code in fill.js and usage.js at the same time, because corrector.add is async operation, and at point in time when you try to correct misspelled word, the right spelled word may be not in a dictionary

i might add support for callback to corrector.add operation, but in real-world cases it isn't necessary

methods

adding words to a dictionary

corrector.add ('word1', 'word2');
corrector.add (['word3', 'word4']);

trying to correct

corrector ('mispelled', function (err, result) {
	console.log (result); // -> ['right spelled'];
});
corrector (['mispelled', 'mispelled2'], function (err, result) {
	console.log (result); // -> ['right spelled1', 'right spelled2'];
});

###some statistics###

array of all possible letters in words (useful in quick-checking existance of a word)

corrector.getLetters (function (err, letters) {
	// same as client.smembers ('_LETTERS_');
	console.log (letters) // -> ['w','e','r','p','r','o','m','i','s','d','j','t','p','a','k','s','w','1', '2','3','4'];
});

maximum length of a word in dictionary

corrector.getMaxLength (function (err, maxLength) {
	// same as client.get ('_MIN_LENGTH_');
	console.log (maxLength) // -> 24
});

minimum length of a word in a dictionary

corrector.getMinLength (function (err, minLength) {
	// same as client.get ('_MAX_LENGTH_');
	console.log (minLength) // -> 4
});

advanced

algorithm leverages n-grams and Dice's coefficient, whatever does it means

you can change some parameters by setting corrector.n = Number|0 and corrector.ranking = function (word1, word2) {return Number|0}

n is for n-grams (trigrams by default)

ranking is for words metric distance (dice coefficient by default)

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago