使用symspellpy的拼写检查器

2024-05-18 15:46:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个拼写检查器,如果有任何错误,它可以纠正用户输入。 我使用symspellpy和海关数据库作为字典

from symspellpy import SymSpell

sym_spell = SymSpell()
corpus_path = 'D:\Pursuit soft\dict\words2.txt'
sym_spell.create_dictionary(corpus_path)

print(sym_spell.words)

现在,当我将其与以下代码一起使用时

from symspellpy import SymSpell, Verbosity
input_term='cmments'
suggestions = sym_spell.lookup(input_term, Verbosity.CLOSEST,
                               max_edit_distance=2, include_unknown=True)

for suggestion in suggestions:
    print(suggestion)

结果是: “cmments”变成了“comments,1,8”…这是正确的..但我只是单词,而不是距离和频率..如何只提取单词


Tags: pathfromimportinputcorpusprinttermspell

热门问题