A JavaScript spell-checker

This page serves as a playground for the JavaScript spell-checker implementation. For details about the algorithm, read the original article by Peter Norvig. Using it is a two-step process: 1) train the algorithm, 2) request corrections.

Before using the spell-checker, the algorithm must be trained first. If you click on the 'correct' button before that, the algorithm will be unable to find the correct spelling in any word you try. Training involves loading a file with many words (about a million in this case) and building a language model. This file is the same one used by Norvig. You can click on the 'train' button to do it (note that your browser may become unresponsive for a few seconds):

With the spell-checking engine trained, we can now request corrections for any words we want. You can enter a misspelled word in the input box below and then click on the 'correct' button to correct it:

After playing a little with some words, you may want to run the tests in the original article. These tests apply the trained algorithm to a set of misspelled words and evaluate the performance of the implementation. The original results from Peter Norvig's Python implementation were:

Test 1: {'bad': 68, 'bias': None, 'unknown': 15, 'secs': 16, 'pct': 74, 'n': 270}
Test 2: {'bad': 130, 'bias': None, 'unknown': 43, 'secs': 26, 'pct': 67, 'n': 400}

Note that due to the long duration of these tests, in order to avoid slow script warnings, the test implementation relies on Web Workers that are currently only supported in Firefox 3.5, Safari 4 and Chrome 3.