This might be fun to look at, seen that you tagged your question with machine learning:
http://norvig.com/spell-correct.html
It's a fascinating read. On the other hand, if you are not looking to tinker, a better one might be Enchant, have a look at