In our previous recipe, we saw how difflib
can compute the similitude between two strings. This means that we can compute the similitude between two words and suggest corrections to our users.
If the set of correct words is known (which usually is for any language), we can first check if the word is in this set and, if not, we can look for the most similar one to suggest to the user the right spelling.
The steps to follow this recipe are:
- First of all we need the set of valid words. To avoid bringing in the whole English dictionary, we will just sample some words:
dictionary = {'ability', 'able', 'about', 'above', 'accept', 'according', 'account', 'across', 'act', 'action', 'activity', 'actually', 'add', 'address', 'administration', 'admit', 'adult', 'affect', 'after', 'again', 'against', 'age', 'agency', 'agent', 'ago', 'agree', 'agreement...