How to Check Spellings of Given Words using Enchant in Python
Python has a module named Enchant, which is used for checking the spellings of the word and giving suggestions for corrections. It also gives options for antonym and synonym of the words. It can also check in the dictionary if a word exists or not.
The check() function returns "true" if the given the word is present in the language dictionary; otherwise, it will return "false". We can also use this functionality of the check() function for checking the spelling of the words.
In Enchant module, we can also use suggest() function for correcting spellings of the incorrectly spelled word.
In this tutorial, we will see an example to understand the usage of Enchant module in Python for checking in spellings of the given the word and suggestions for correct spellings.
To install Enchant module, we can use the following command:
Collecting pyenchant Downloading pyenchant-3.2.2-py3-none-win_amd64.whl (11.9 MB) Installing collected packages: pyenchant Successfully installed pyenchant-3.2.2
Example: To check the spelling of the words and get suggestions for corrections
The misspelled words in the list are : ['Cer', 'Peaple', 'Dronk', 'Beur', 'Plut'] Suggestion for misspelledCer : ['Ce', 'Cr', 'Er', 'Cher', 'Cerf', 'Ser', 'Ter', 'Cor', 'Cdr', 'Der', 'Ger', 'Per', 'Chr', 'Her', 'Yer'] Suggestion for misspelledPeaple : ['Peale', 'People', 'Leaper', 'Plea'] Suggestion for misspelledDronk : ['Cronk', 'Drink', 'Drone', 'Drank', 'Drunk', 'Drongo'] Suggestion for misspelledBeur : ['Bur', 'Beer', 'Bear', 'Blur', 'Eur'] Suggestion for misspelledPlut : ['Pluto', 'Slut', 'Prut', 'Glut', 'Pl ut', 'Pl-ut', 'Plur', 'Put', 'Plus', 'Plat', 'Plot', 'Pout', 'Plug', 'Plum']
In this tutorial, we discussed how to install, and use Enchant module for checking the spellings of the given words and get suggestions for misspelled words.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week