Skip to content

Basic spell-checker / spelling correcter module for Nodejs.

Notifications You must be signed in to change notification settings

mrmarbles/wordsworth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wordsworth

Spell-checker / spelling correcter module for Nodejs based off of Peter Norvig's spelling corrector publication (http://norvig.com/spell-correct.html) and John Resig's instructions on string-based binary searching (http://ejohn.org/blog/revised-javascript-dictionary-search/).

Installation

 npm install wordsworth

Use

Asynchronous Initialization

The sample /data/en_US/seed.txt and /data/en_US/training.txt files are fairly large and as such have been compressed and provided in an archive located in /data/. To run the examples, extract the contents of the archive into /en_US.

var sp = require('wordsworth').getInstance();

sp.initialize(

  '../data/en_US/seed.txt',
  '../data/en_US/training.txt', function() {

    console.log('Initialized!');

    // indicates whether or not the spell-checker knows the given word
    console.log(sp.exists('hello'));
    console.log(sp.exists('polymorphism'));

    /**
     * Accepts a single word and will return an ordered Array, most probable to
     * least probable, of suggested spelling corrections IF the given word has been
     * mis-spelled.
     */
    console.log(sp.suggest('polymrphism'));

    /**
     * Will return an Object containing keys representing any misspelled
     * words in the provided text along with an ordered Array of potential
     * spelling corrections for each key.
     */
    console.log(sp.analyze('This sentense will havv a fiw speling errorrs.'));

  }
);

Synchronous Initialization

var sp = require('wordsworth').getInstance();

var seeds = ['one', 'two', 'three']; // language dictionary, one word per array index
var training = [
    'large amounts of training text',
    'ideally one sentence per array index'
];

sp.initializeSync(seeds, training);
sp.exists('one');
sp.suggest('some mis-spelled word');

Testing

npm test

Contributors

license

MIT License

About

Basic spell-checker / spelling correcter module for Nodejs.

Resources

Stars

Watchers

Forks

Packages

No packages published