Spelling Corrector in 21 lines of Python
norvig.com
norvig.com
A surprise is that the Perl implementation weighs in at 63 lines. I would have expected much less. I expect a much shorter version is possible, relying on idiomatic constructs at the expense of readability.
http://www.partario.com/blog/2009/10/a-spelling-corrector-in...
https://github.com/timrobinson/spell-correct/blob/master/Cor...
Check out the Tf-Idf weight for getting an idea on how to do that: http://en.wikipedia.org/wiki/Tf%E2%80%93idf
A useful trick based on the technique you describe: build vectors where each dimension represents a user in the system (1 means the user visited that web page); since people are interested in a narrow array of topics. Furthermore you can extend this to find similar users.
Amazon does this to find similar or complementary products.
Very interesting to see how other have tackled this programming problem.
But the comparison may not be fair, as the Java author may have tweaked the algorithm or added new features
e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS def known_edits2(word):
L = []
for e1 in edits1(word):
for e2 in edits1(e1):
if e2 in NWORDS:
L.append(e2)
return set(L)Some discussion here : http://stackoverflow.com/questions/1564184/edit-distance-alg...
However, for English nothing beats soundex type algo. I believe major SQLs and php do soundex.
Soundex is an old algorithm, century old, designed to find immigrants by their last name, no matter how they converted it from their native language to english. For example: if one came and had name Szczybliewski or had it Shcheeblevsky , then soundex should return close match.
Metaphone is improved version of soundex (available in php). And if you are careful, you can find double-metaphone out there.
Kind regards
The examples in Future Work 2 would all have been resolved by checking results against Soundex, a simple check with significant improvement.
There are two classes of errors: misspellings and typos. Edit distance (Levenshtein) is reasonable for typos, while the examples in Future Work 2 are misspellings.
Another trivial improvement is to weight edit distance by typo distance.
I'm down as 22 lines of C#, though to be fair I am cheating vastly and the lines are huge :)
http://www.codegrunt.co.uk/2010/11/02/C-Sharp-Norvig-Spellin...
C# does offer some nice features to give you some succinctness but there's no getting away from the verboseness of a java-like language.