Enchant是python中的一個模塊,用於檢查單詞的拚寫,並提供糾正單詞的建議。另外,給出單詞的反義詞和同義詞。它檢查字典中是否存在單詞。
enchant .DictWithPWL()
enchant.DictWithPWL()
是一種內置方法enchant
模塊。它用於組合語言詞典和自定義詞典,也稱為“個人單詞列表”(PSL)。
用法: enchant.DictWithPWL(tag, text_file)
參數:
標簽:語言詞典的代碼
text_file:包含要包含的單詞的文本文件的路徑,每行一個單詞。
返回:Dict對象
例:
樣本文件“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
相關用法
注:本文由純淨天空篩選整理自Yash_R大神的英文原創作品 enchant.DictWithPWL() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。