(def known (words) (dedup:keep [nwords _] words)) ; lines count is now 12
(def correct2 (word (o f [nwords _]))
(most f
(or (known:list word) (known:edits1 word) (known:edits2 word) (list word))))
Or:
(def correct3 (word (o f [nwords _])) ; don't need 'known, but require aspirin
(most f (or ((apply orf (map [fn (w) (dedup:keep [nwords _] (_ w))]
(list list edits1 edits2)))
word) (list word))))
arc> (correct{2/3} "yellow")
yellow
arc> (correct{2/3} "godd")
good
arc> (correct{2/3} "speling")
spelling
arc> (correct{2/3} "unnkknnoown")
unnkknnoown
Not exactly the same results than Norvig's version (>>> correct("speling") -> "sling" / "godd" -> "god") but I tested the Ruby version linked on his site, and it yields the same results. Note that the result for "speling" is not really good in canonical version. Maybe it's because the order on Python sets is different from the one in Ruby/Arc lists. I should port the test program of Norvig to stop worrying, but it's OK for now. For now, let's say this version is better than the Norvig's one (!!!)