How to Check Spellings of Given Words using Enchant in Python

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.

Installation:

To install Enchant module, we can use the following command:

Output:

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

Output:

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']

Conclusion

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.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263283.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论