Re: Soundex
Posted in 1992
Topics: General Discussion
Hi all. Re: Soundex > Knuth, Vol 3., p.392-393 describes the Soundex algorithm > as well as gives references to the original paper. > > Anil > > -- > Reply to nair@quintus.com nair@quintus.uucp Yes. Here is a nice implemenation of soundex for everyone: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /* * Reference: Adapted from Knuth, D.E. (1973) The art of computer programming; * Volume 3: Sorting and searching. Addison-Wesley Publishing Company: * Reading, Mass. Page 392. * * 1. Retain the first letter of the name, and drop all occurrences of * a, e, h, i, o, u, w, y in other positions. * * 2. Assign the following numbers to the remaining letters after the first: * b, f, p, v -> 1 l -> 4 * c, g, j, k, q, s, x, z -> 2 m, n -> 5 * d, t -> 3 r -> 6 * * 3. If two or more letters with the same code were adjacent in the original * name (before step 1), omit all but the first. * * 4. Convert to the form ``letter, digit, digit, digit'' by adding trailing * zeros (if there are less than three digits), or by dropping rightmost * digits (if there are more than three). * * The examples given in the book are: * * Euler, Ellery E460 * Gauss, Ghosh G200 * Hilbert, Heilbronn H416 * Knuth, Kant K530 * Lloyd, Ladd L300 * Lukasiewicz, Lissajous L222 * * Most algorithms fail in two ways: * 1. they omit adjacent letters with the same code AFTER step 1, not before. * 2. they do not omit adjacent letters with the same code at the beginning * of the name. * */ #include <ctype.h> #define SDXLEN 4 char *soundex(name) char *name; { static char buf[SDXLEN+1]; static char map[] = "01230120022455012623010202"; register char mc, uc, pc = '0'; register int idx; strcpy(buf,"Z000"); for (idx = 0; *name && idx < SDXLEN; name++) if (isalpha(*name)) { uc = toupper(*name); mc = map[uc-'A']; if (idx == 0 || (mc != '0' && mc != pc)) { buf[idx] = idx ? mc : uc; idx++; } pc = mc; } return(buf); } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> We use it to implement a soundex search screen for finding party records in court databases. Store the four byte soundex value of each party's last name in a hidden soundex field. Btree the soundex field and make a special soundex search screen that accepts query by example fields such as last name, first name, DOB etc. On find, the screen intercepts the last name spelling that the uses types in and instead searches on the last name soundex value. Really slick and very fast. Enjoy! - John John Gorman john@rsi.com Relational Semantics, Inc. Phone: 1 617 926 0979 17 Mount Auburn Street Watertown MA USA Nothing happens.