Skip to content

Instantly share code, notes, and snippets.

View benshimmin's full-sized avatar
🇪🇺
Bare ruin'd choirs, where late the sweet birds sang

Ben Shimmin benshimmin

🇪🇺
Bare ruin'd choirs, where late the sweet birds sang
View GitHub Profile
@benshimmin
benshimmin / spelling_corrector.coffee
Last active August 29, 2015 14:11
Peter Norvig's famous spelling corrector, in CoffeeScript (with Underscore)
# A CoffeeScript version of http://norvig.com/spell-correct.html
[fs, _] = [require("fs"), require("underscore")]
words = (text) -> text.toLowerCase().match /[a-z]+/g
train = (features) ->
model = {}
_.each features, (f) -> if model[f] then model[f] += 1 else model[f] = 1
model