[erlang-questions] Suggestion for a spell corrector implementation

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Tue May 15 12:52:00 CEST 2007


Here's a suggestion for transposition_edits(), that 
I find a little bit more intuitive:

transposition_edits(Word) ->
  Transpose = fun(P) -> 
      lists:concat([string:sub_string(Word,1,P),
                    lists:reverse(
                       string:sub_string(Word,P+1,P+2)),
                    string:sub_string(Word,P+3)])
     end,
  [Transpose(P) || P <- lists:seq(0,length(Word)-2)].

(Not making any claims about it being efficient or 
anything - it's probably efficient enough.) 

BR,
Ulf W

> -----Original Message-----
> From: erlang-questions-bounces@REDACTED 
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of 
> Federico Feroldi
> Sent: den 14 maj 2007 19:12
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] Suggestion for a spell corrector 
> implementation
> 
> Hello everybody,
> following the Spell Corrector implementation in 20 lines of 
> Python code made by Peter Norvig 
> (http://www.norvig.com/spell-correct.html) I wanted to try an 
> Erlang one, here's what I did:
> 
> http://www.pixzone.com/blog/223/spell-corrector-aka-google-sug
gest-in-erlang-first-part/
> 
> It's a bit more that 20 lines of code but it can be probably 
> refactored and optimized, I'm open to any suggestions on how 
> to improve the code!
> 
> thanks
> 
> -federico
> 
> http://www.pixzone.com/blog/
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list