拼写校正器在 Python 中无法正常工作

Spell corrector not working properly in Python

我的自动更正模块有问题,尤其是函数 spell(word): 这是我用的class

class SpellCorrector(PreprocessModule):

    def process(self, text):
        result = ""
        for word in text.split():
            result = result + spell(word) + " "

        return result

测试是:

st = "Ehi thia ia a beautiful dau"
    for w in st.split():
        print(spellCorrector.process(w))

输出为:

"Eh Thia ia a beautiful dau"

所以,它似乎工作得不太好,而且速度非常慢。

使用过Python模块"autocorrect"的朋友们,这正常吗?我忘记了什么吗?对其他拼写检查器有什么建议吗?

提前致谢

我推荐使用的是Peter Novig's拼写校正。它使用 Probability Theory

下面的代码首先检查它是否是英文单词。如果不是,则转到属于 peter 算法的校正方法

  def spell_correct(text):
        try:
            output = ""
            splited_words = text.split()
            d = enchant.Dict("en_US")
            for i in splited_words:
                if d.check(i):
                    output = output + i + " "
                else:
                    output = output + correction(i) + " "
        except Exception as e:
            print(e)
        return output