1 #------------------------------------------------------------------------------ 2 # 3 # soundex.io -- generate soundex encodings. 4 # 5 # 1. Keep the first letter. 6 # 7 # 2. Drop all the vowels A E I O U W Y H. 8 # 9 # 3. Encode the remaining 3 letters into: 10 # 11 # B P F V 1 12 # C S K G J Q X Z 2 13 # D T 3 14 # L 4 15 # M N 5 16 # R 6 17 # 18 # 4. Double letters are treated as one. 19 # 20 # 5. Double letters with same encoding is treated as one. 21 # 22 # 23 # Tov Are Jacobsen April, 2003 24 # 25 # Language: http://www.iolanguage.com 26 # Version: 2005-01-19 (Jon Kleiser) 27 #------------------------------------------------------------------------------ 28 Soundex := Object clone do( 29 encmap := Map clone do( 30 atPut("B", 1) 31 atPut("P", 1) 32 atPut("F", 1) 33 atPut("V", 1) 34 atPut("C", 2) 35 atPut("S", 2) 36 atPut("K", 2) 37 atPut("G", 2) 38 atPut("J", 2) 39 atPut("Q", 2) 40 atPut("X", 2) 41 atPut("Z", 2) 42 atPut("D", 3) 43 atPut("T", 3) 44 atPut("L", 4) 45 atPut("M", 5) 46 atPut("N", 5) 47 atPut("R", 6) 48 ) 49 ) 50 #========================================================================= 51 # 52 # Converts a string into soundex encoding. 53 # 54 # Arguments: 55 # name String containing a surname 56 # 57 #========================================================================= 58 Soundex encode := method(name, 59 name = name upper 60 ename := "" 61 name foreach(i, s, 62 if (i == 0) then ( 63 ename = ename append(s asCharacter) 64 ) else ( 65 # Drop all unmapped characters 66 code := encmap at(s asCharacter) 67 if (code != Nil, 68 if (code asString != ename at(-1) asCharacter, 69 ename = ename append(code) 70 if (ename length == 4, return ename) 71 ) 72 ) 73 ) 74 ) 75 return ename 76 )