diningphil diningphil - 3 months ago 27
Python Question

Spell corrector not working properly in Python

I have a problem with the autocorrect module, in particular the function spell(word):
Here there's the class I use

class SpellCorrector(PreprocessModule):

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

return result

The test is:

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

And the output is:

"Eh Thia ia a beautiful dau"

So, it seems not to work so well, and it is remarkably slow.

For those of you who have used the module "autocorrect" in Python, is this normal? Am I forgetting something? Any suggestion on other spell checkers?

Thanks in advance


What I recommend to use is Peter Novig's spell correction. It uses Probability Theory

Below code first check if it is a english word or not. If not it goes to correction method that belongs to peter's algorithm

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