I recently wrote an article about a program I wrote which tries to suggest corrections to input. The idea was for command-line parameters, although it could, in theory, be used for any kind of input (even auto-correction in a text editor, although it would be really slow to operate on an exhaustive dictionary).
I got the idea from git(3). When you commit to the repository in git(3) you type git commit. If you mistype "commit" as "comit" git will produce the following output:
$ git comit
git: 'comit' is not a git command. See 'git --help'.
Did you mean this?
commit
That's what I'm trying to achieve with my 'correct' program.
The thing is, I'm not entirely sure how "correct" the program is (excuse the pun :). Could I get some feedback on it? (i.e., does it work? how valid is the algorithm in the similarity() function? how could the program in general be improved? is there a simpler way that I'm missing?). One feature I'd like to add would be for the program to express its confidence that the suggestion is correct. Another would be to have a threshold for how close the strings have to be to qualify as valid suggestions.
There's a more advanced version, called the Damerau-Levenshtein algorithm. It's a bit softer on 'common mistypes' such as two letters in the wrong sequence ('wrong' <-> 'worng'). The Levenshtein distance would be 2 (substitute o for r, and r for o), while the DL distance would be 1 (swap o and r).