【问题标题】:Spell corrector not working properly in Python拼写校正器在 Python 中无法正常工作
【发布时间】:2016-11-06 08:35:33
【问题描述】:

我的自动更正模块有问题,尤其是功能 spell(word): 这是我使用的类

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 中使用过“自动更正”模块的人来说,这是正常的吗?我是不是忘记了什么?对其他拼写检查器有什么建议吗?

提前致谢

【问题讨论】:

  • 你想从中得到什么输出?

标签: python spell-checking autocorrect


【解决方案1】:

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

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

  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

【讨论】:

  • 你必须导入什么才能正确使用方法 correction( ) ?我导入了附魔,但更正不在我的程序范围内。顺便说一句,我还阅读了基于 Norvig 实现的自动更正模块……有点奇怪。
  • 彼得诺维格算法中的修正方法。将该代码添加到您的脚本中。我给了你调用方法。您需要在代码中设置 Peter novig 算法
  • 你的解决方案实际上并不是一个解决方案,因为代码的核心是更正部分。将附魔的使用与 Norvig 的算法相结合。将是一个解决方案
  • 我在回答中提到的。我的代码调用彼得算法的函数并将字符串构造为输出
猜你喜欢
  • 2012-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多