alexander-bauer/swirlypy

Write a fill-in-the-blanks question type which tolerates typos.

WilCrofter opened this issue · 0 comments

Peter Norvig wrote a 21 python line spelling corrector which covers 80%-90% of English misspellings. The core of it is edits1:

def edits1(word):
   splits     = [(word[:i], word[i:]) for i in range(len(word) + 1)]
   deletes    = [a + b[1:] for a, b in splits if b]
   transposes = [a + b[1] + b[0] + b[2:] for a, b in splits if len(b)>1]
   replaces   = [a + c + b[1:] for a, b in splits for c in alphabet if b]
   inserts    = [a + c + b     for a, b in splits for c in alphabet]
   return set(deletes + transposes + replaces + inserts)

Incorporating a simple spelling correct such as this one could make fill-in-the-blanks questions viable.