Here is one approach to doing spelling corrections/coercions

corrections =: 0 : 0
USA;United States;U.S.A.;US;
UK;U.K.;
)
 c=: <  ;. _2 each < ;. _2 corrections

spellcorrect =: c & (( (<'Unknown Country'),~ {.("1)(&>)@:[) {~ 1: i.~ <@:] 
+/"1@:e.~ >@:[)

   spellcorrect 'UK'
┌──┐
│UK│
└──┘
   spellcorrect 'U.K.'
┌──┐
│UK│
└──┘
   spellcorrect 'U.Kong'
┌───────────────┐
│Unknown Country│
└───────────────┘
   spellcorrect 'U.S.A.'
┌───┐
│USA│
└───┘


Would you change/improve the spellcorrect verb?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to