Saturday, November 16, 2024
Google search engine
HomeLanguagesenchant.DictWithPWL() in Python

enchant.DictWithPWL() in Python

Enchant is a module in python which is used to check the spelling of a word, gives suggestions to correct words. Also, gives antonym and synonym of words. It checks whether a word exists in dictionary or not.

enchant.DictWithPWL()

enchant.DictWithPWL() is an inbuilt method of enchant module. It is used to combine a language dictionary and a custom dictionary also known as Personal Word List(PSL).

Syntax : enchant.DictWithPWL(tag, text_file)

Parameter :
tag : the code of the language dictionary
text_file : the path of the text file which contains the words to be included, one word per line.

Returns : a Dict object

Example :

The contents of the sample file “PWL.txt” are:

qwerty
jabba
gfg




# import the enchant module
import enchant
  
# dictionary with only en_US
d = enchant.Dict("en_US")
  
# the word to be searched
word = "gfg"
  
# check whether the word is in the dictionary
if d.check(word):
    print("The word "+ word + " exists in the dictionary")
else:
    print("The word "+ word + " does not exists in the dictionary")
  
# the path of the text file
file_path = "PWL.txt"
  
# instantiating the enchant dictionary
# with DictWithPWL()
d = enchant.DictWithPWL("en_US", file_path)
  
# checking whether the word is
# in the new dictionary
if d.check(word):
    print("\nThe word "+ word + " exists in the dictionary")
else:
    print("\nThe word "+ word + " does not exists in the dictionary")


Output :

The word gfg does not exists in the dictionary

The word gfg exists in the dictionary

Last Updated :
03 Jun, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments