home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2313 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  12.4 KB

  1. Xref: sparky comp.programming:2313 alt.msdos.programmer:2200 comp.sys.ibm.pc.programmer:337 comp.unix.programmer:4296
  2. Newsgroups: comp.programming,alt.msdos.programmer,comp.sys.ibm.pc.programmer,comp.unix.programmer
  3. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbfsb!cbnewsc!cbnews!eotto
  4. From: eotto@cbnews.cb.att.com (erick.otto)
  5. Subject: Soundex algorithms /With code 'C' etc.
  6. Organization: AT&T
  7. Date: Fri, 14 Aug 1992 12:09:13 GMT
  8. Message-ID: <1992Aug14.120913.26413@cbnews.cb.att.com>
  9. Followup-To: poster
  10. Keywords: soundex, papers, code
  11. Lines: 281
  12.  
  13.  
  14. All,
  15.     Thank you very much everyone who replied to my requests for the soundex
  16.     code/algorithms.
  17.  
  18.     I have promised to post all the outcome and have combined all the stuff
  19.     I could find in the below posting.
  20.     I contains various articles on the soundex algoritm.
  21.     The next article should contain various code fragments (functions)
  22.     that produce soundex codes, pick the ones you like.
  23.  
  24.     P.S. The code is cpio'ed and uuencoded
  25.  
  26.  
  27. Erick Otto
  28. eotto@cbnews.att.com
  29. ------------------------- Article 1 -------------------------------------------
  30. 1. Retain the first letter of the name and drop all occurrances
  31.    of a, e, h, i, o, u, w, y in other positions.
  32.  
  33. 2. Assign the following numbers to the remaining letters after
  34.    the first:
  35.    b, f, p, v ---> 1
  36.    c, g, j, k, q, s, x, z ---> 2
  37.    d, t ---> 3
  38.    l ---> 4
  39.    m, n ---> 5
  40.    r ---> 6
  41.  
  42. 3. If two or more letters with the same code were adjacent in the
  43.    original name (before step 1) omit all but the first.
  44.  
  45. 4. Convert to the form "letter, digit, digit, digit" by adding
  46.    trailing zeros (if there are less than 3 digits) or by dropping
  47.    rightmost digits (if there are more than three).
  48.  
  49.         "The Art of Computer Programming, Sorting and Searching"
  50.         Knuth, Donald, Addison-Wesley, 1973, pp. 391-392.
  51.  
  52. ------------------------- Article 2 -------------------------------------------
  53. The algorithm is very simple,
  54.  
  55. 1:  Assign number values to all but the first letter of the
  56. word, using this table
  57.    1 - B P F V
  58.    2 - C S K G J Q X Z
  59.    3 - D T
  60.    4 - L
  61.    5 - M N
  62.    6 - R
  63.    7 - A E I O U W H Y
  64.  
  65. 2: Apply the following rules to produce a code of one letter and
  66.    three numbers.
  67.    A: The first letter of the word becomes the initial character
  68.       in the code.
  69.    B: When two or more letters from the same group occur together
  70.       only the first is coded.
  71.    C: If two letters from the same group are seperated by an H or
  72.       a W, code only the first.
  73.    D: Group 7 letters are never coded (this does not include the
  74.       first letter in the word, which is always coded).
  75.  
  76. Of course, this can be used without the numeric substitution to
  77. produce abbreviations also, but the numbers indicate the phonemic
  78. similarity (e.g. Bear = Bare = B6), or Rhymes (e.g. Glare = G46,
  79. Flair = F46).  This can also be useful for finding duplicate entries
  80. in a large database, where a name may be slightly mis-spelled (e.g.
  81. Smith = Simth = S53).
  82.  
  83. ------------------------- Article 3 -------------------------------------------
  84. I've written a soundex program based on the rules in Knuth's _Searching_and_
  85. Sorting.  These are also the rules used at the National Archives to sort
  86. census data.  These rules differ slightly from the ones posted by Mr. Stewart.
  87. If you don't need to match anyone else's soundex, the most important rule is
  88. to be consistent.  I will insert Knuth's rules below.
  89. The algorithm is very simple,
  90.  
  91. 1. Retain the first letter of the name, and drop all occurrances of a, e, h,
  92. i, o, u, w, y in other positions.
  93.  
  94. 1:  Assign number values to all but the first letter of the
  95. word, using this table
  96.    1 - B P F V                                    2 - C S K G J Q X Z
  97.    3 - D T                                        4 - L
  98.    5 - M N                                        6 - R
  99.    7 - A E I O U W H Y
  100.  
  101. 2. Assign number values as above, except for 7.
  102.  
  103. 2: Apply the following rules to produce a code of one letter and
  104.    three numbers.
  105.    A: The first letter of the word becomes the initial character
  106.       in the code.
  107.    B: When two or more letters from the same group occur together
  108.       only the first is coded.
  109.    C: If two letters from the same group are seperated by an H or
  110.       a W, code only the first.
  111.  
  112. 3. If two or more letters with the same code were adjacent in the original
  113. name (begore step 1), omit all but the first.
  114.  
  115.    D: Group 7 letters are never coded (this does not include the
  116.       first letter in the word, which is always coded).
  117.  
  118. 4. Convert to the form "letter, digit, digit, digit" by adding trailing
  119. zeros or dropping rightmost digits.
  120.  
  121.  
  122. BTW according to the reference in Knuth's book, this algorithm was
  123. developed by Margaret Odell and Robert Russell in 1922.
  124. ------------------------- Article 4 -------------------------------------------
  125. transcribed from ACIUS tech note TN-06
  126. (c) 1992 ACIUS Inc
  127.  
  128. INTRODUCTION
  129.  
  130. This technical note will show you how to use 4th Dimension code to
  131. build phonetic equivalent for an alphanumeric field.  It will give you
  132. phonetic searching capabilities in your databases.
  133.  
  134. About the Soundex Function
  135.  
  136. In order to acheive phonetic searching, we use an algorithm calles
  137. "Soundex."  This algorithm converts a string of characters into a
  138. phonetic equivalent by grouping together characters that sound alike
  139. and assigning a single digit to each of them.  The procedure allows
  140. you to convert any passed string to its phonetic equivalent, thus
  141. allowing you to adjust the phonetic precision.
  142.  
  143. The following four points must be taken into consideration when using
  144. the "Soundex" function.
  145.  
  146. The user must always know the correct first character:  The algorithm
  147. creates the phonetic equivalent with the first character of the
  148. phonetic equivalent that is equal to the first character of the
  149. original string.
  150.  
  151. Each character is read and assigned a number:  This number is
  152. associated with a group; charaters are grouped according to their
  153. sounds.  For example, group six contains characters "m" and "n"
  154. because they sound alike.  We have set up a common grouping in
  155. "Changing Character Sound Grouping," but you may change this as you
  156. feel necessary.
  157.  
  158. While converting the string to its phonetic equivalent:  If character
  159. n+1 is in the same group as character n, character n + 1 is ignored.
  160.  
  161. The second paramater of the procedure determines the precision of the
  162. phonetic equivalent:  By default, it is set to three different groups
  163. of character sounds.  If you increase the precision, it will be more
  164. discriminating in determining phonetic matches.  For example, if you
  165. have a precision of three and build a phonetic equivalent for the word
  166. "monitor," searching for a similar word, like "monita," will return a
  167. match.  However, if you have a precision of six, a match will not be
  168. found.  We have found a precision of three or four gives the best
  169. results.
  170.  
  171. Soundex Function
  172.  
  173. The operation of the code is quite straightforward.  This procedure
  174. walks backwards down the string until it runs into either a colon or
  175. the end of the string.  The Soundex function returns a string that can
  176. be used as the phonetic representation of a give string.  This
  177. function returns a result of <0 if an error has occurred.
  178.  
  179. Changing the Character Sound Groupings
  180.  
  181. In the Soundex function, we group characters together that sound alike
  182. and then assign an interfer to them.  Examine the lines of code:
  183.  
  184. $Sounds:= "aehiouwybfpvcgjkqsxzdtlmnr"        `Group chars that sound alike
  185. $SoundsI:="11111111222233333333445667"        `Assign numbers for each group
  186.  
  187. Each letter is given a specific code, as shown in the following table.
  188.  
  189. Letter            Soundex Code
  190. a,e,h,i,o,u,w,y        1
  191. b,f,p,v            2
  192. c,g,j,k,q,s,x,z        3
  193. d,t            4
  194. l            5
  195. m,n            6
  196. r            7
  197.  
  198. You can regroup these characters as you like.  $SoundsI contains the
  199. numerical equivalent for each character in $Sounds.  If you wanted to
  200. group "aeh" in its own separate group, you would declare the two
  201. variables as follows:
  202.  
  203. $Sounds:= "aehiouwybfpvcgjkqsxzdtlmnr"        `Group chars that sound alike
  204. $SoundsI:="11122222333344444444556778"        `Assign numbers for each group
  205.  
  206. Following this simple rule, you can recreate your own soundex
  207. groupings for your specific phonetics.
  208.  
  209. [4D specific examples deleted]
  210.  
  211. Usage:
  212.  
  213. Apply the soundex function to fields in your database you will
  214. phonetic search against, and store the results in another field in the
  215. same table, i.e.
  216.   Name    (filed to search against)
  217.   SNDX_Name := soundex(Name)
  218. Then, when user wants to do a sounds alike search, translate the
  219. user's input to soundex string and look for matches
  220.   SNDX_input:=soundex(Input)
  221.   select * from TABLE where SNDX_Name = SNDX_input
  222.  
  223. ------------------------- Article 5 -------------------------------------------
  224. The Soundex algorithm described by two previous follow-ups is only
  225. the best-known of sounds-like alorithms.  It is tied to single-language
  226. assumptions, which may be violated in the CD-Disc application cited.
  227.  
  228. A proprietary algorithm which is available for license and as a
  229. product which might fit that application better is Proximity
  230. Technology's Proximity Search algorithm.  They have a (patented) VLSI
  231. accelerator chip which used to be necessary (on old PC-ATs) if the
  232. database grew larger than trivial (400 records); a modern 486 might
  233. not need one, I don't know.  Their "Friendly Finder" would list the
  234. 10 to 20 records which most closely match the key you are typing,
  235. with the list changing as you extend the key, character by character --
  236. like incremental-search mode in emacs, only it shows 20 matching lines,
  237. like list-matching-lines.  Usually there are a few records in the list
  238. that you don't understand why their algorithm thinks they're a close
  239. match, but what you want is almost always on page 1.  In 1986, Friendly
  240. Finder would scan DBase II and III and ASCII files.  I suppose
  241. they may have upgraded it for DBase IV.
  242.  
  243. They will also license to developpers to use the library & hardware
  244. in your programs -- but for a customer-inquiry device, the pop-up
  245. database-searcher may be just right -- you can paste the product
  246. number from the searcher into the order-entry program, I think!
  247.  
  248. The company exists to exploit their two resources: the Proximity
  249. Search Algoritm in hardware and software, and their exclusive
  250. licesinsing arrangement with Merriam-Webster's lexicographic database.
  251. (Yes, that pocket-dictionary/spell-checker/thesaurus that has the
  252. MW logo on it has the Proximity algorithm in it, and probably has 
  253. their logo in fine print too.)
  254.  
  255. To contact them: in 1986, they had an office in Framingham Mass,
  256. which I visited as an Evil Defense Contractor looking for useful
  257. technologies for databases (they already had a contract with NSA
  258. for use of their VLSI chip in something hush-hush, but that had
  259. little to do with me except provide a handle for checking references
  260. if I got my sponsor interested); it may still be there if you call
  261. 508-555-1212.  Their literature listed home office as:
  262.     Proximity Technology Inc.
  263.     3511 NE 22nd Avenue
  264.     Fort Lauderdale, FL 33308-6226
  265.     305-566-3511   (FAX: -2088)
  266.     TELEX 160054 PRXMTY
  267.  
  268.  
  269. Disclaimer: My only remuneration from them was a Beta copy of the
  270. thesaurus that my wife was supposed to review, but never used due to
  271. lack of a harddrive to install it on and a trial (no hardware) copy of
  272. Friendly Finder for evaluation.  Hmmm.  Maybe I should install those
  273. again, they are nice programs.  I wonder how it would work on my 
  274. 1E4 record book catalogue on the super-486 at the office?
  275. ------------------------- Article 6 -------------------------------------------
  276. Actually there was an interesting article in the C-users journal of june or
  277. july about string comparisons with unequal lengths and approximating how much
  278. they differ and listing the strings(or records) that have an acceptable
  279. difference.
  280. *****************************************************************************
  281. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
  282. *                                                    |                      *
  283. *  ______   _______   _____   _______     -------    | Erick Otto           *
  284. * /  __  \ |__   __| /   _ \ |__   __|  -=====-----  | Network Systems-     *
  285. * | (__) |    | |    \  \ \_\   | |    -=======----- | Netherlands          *
  286. * |  __  |    | |    /   / __   | |    --=====------ | eotto@cbnews.att.com *
  287. * | |  | |    | |   |  (\ / /   | |     -----------  | eotto@hvlpa.att.com  *
  288. * |_|  |_|    |_|    \_____/    |_|       -------    | x'2632, BE118        *
  289. *                                                    |                      *
  290. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
  291. *****************************************************************************
  292.  
  293.  
  294.