📜  Python中的 enchant.DictWithPWL()

📅  最后修改于: 2022-05-13 01:54:47.541000             🧑  作者: Mango

Python中的 enchant.DictWithPWL()

Enchant是Python中的一个模块,用于检查单词的拼写,给出正确单词的建议。此外,给出单词的反义词和同义词。它检查字典中是否存在单词。

附魔.DictWithPWL()

附魔enchant.DictWithPWL()enchant模块的内置方法。它用于组合语言词典和自定义词典,也称为个人词表 (PSL)。

例子 :

样本文件“PWL.txt”的内容是:
# 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