Python中的 enchant.DictWithPWL()
Enchant
是Python中的一个模块,用于检查单词的拼写,给出正确单词的建议。此外,给出单词的反义词和同义词。它检查字典中是否存在单词。
附魔.DictWithPWL()
附魔enchant.DictWithPWL()
是enchant
模块的内置方法。它用于组合语言词典和自定义词典,也称为个人词表 (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
例子 :
样本文件“PWL.txt”的内容是:
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")
输出 :
The word gfg does not exists in the dictionary
The word gfg exists in the dictionary
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。