Issue in ar_spelling_checker(text):

#3
by imjunaidafzal - opened

Hi! @mohamedabdullah ,
You really done a great job. I got an exception while using it and I figure out what's causing it.

You forgot to initialize tmp_corrections, when if not word in vocab: becomes false, exception occur at line 127:
UnboundLocalError: local variable 'tmp_corrections' referenced before assignment

Your code

    120 def ar_spelling_checker(text):
    121     word_l = re.findall('\w{3,}', text)
    122     result = {}
    123     output = []
    124     for word in word_l:
    125         if not word in vocab:
    126             tmp_corrections = get_corrections(word, vocab)
--> 127         if len(tmp_corrections) == 0:
    128             continue

Correction

    120 def ar_spelling_checker(text):
    121     word_l = re.findall('\w{3,}', text)
    122     result = {}
    123     output = []
    124     for word in word_l:
--> 125         tmp_corrections = []
    126         if not word in vocab:
    127             tmp_corrections = get_corrections(word, vocab)
    128         if len(tmp_corrections) == 0:
    129             continue

Make that changes to handle that case.
Thanks

Hi! @imjunaidafzal :)

Thank you for your comment,
I already just merge your PR.

Sign up or log in to comment