Spelling Corrector in Ruby

@nithinbekal

Peter Norvig

How to Write a Spelling Corrector

gem install spellingbee


    require 'spellingbee'
    speller = SpellingBee.new

    speller.correct('speling') #=> 'spelling'
  

Dictionary

Finding Candidates

Delete, Transpose, Replace, Insert

Deletions


  rewd -> .ewd   r.wd   re.d   rew
          ewd    rwd    red    rew

Transpositions


  rewd -> (er)wd   r(we)d   re(dw)
          erwd     rwed     redw

Replacements


rewd -> (a)ewd   (b)ewd   (c)ewd ...
        r(a)wd   r(b)wd   r(c)wd ...
        re(a)d   re(b)d   re(c)d ...
        ...
  

Insertions


rewd -> (a)rewd (b)rewd (c)rewd ... r(a)ewd r(b)ewd ...
  

Benchmarks

Benchmarks


                  Time (s)        Accuracy

      Python        7.0              74 %
      Ruby          1.3              54 %

      (270 tests)
  

Probability


        CLEARK -> CLEAR or CLERK?
  

Probability

61% accuracy

Edit distance = 2

45 seconds

66% accuracy

Well... 89%

ffi-aspell

GNU aspell

gem install spellingbee

github.com/nithinbekal/spellingbee

Thank you!

WowMakers / CrowdStudio / @nithinbekal