123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- (defvar soundex-alist
- '((?B . "1") (?F . "1") (?P . "1") (?V . "1")
- (?C . "2") (?G . "2") (?J . "2") (?K . "2") (?Q . "2") (?S . "2")
- (?X . "2") (?Z . "2") (?D . "3") (?T . "3") (?L . "4") (?M . "5")
- (?N . "5") (?R . "6"))
- "Alist of chars-to-key-code for building Soundex keys.")
- (defun soundex (word)
- "Return a Soundex key for WORD.
- Implemented as described in:
- Knuth, Donald E. \"The Art of Computer Programming, Vol. 3: Sorting
- and Searching\", Addison-Wesley (1973), pp. 391-392."
- (let* ((word (upcase word)) (length (length word))
- (code (cdr (assq (aref word 0) soundex-alist)))
- (key (substring word 0 1)) (index 1) (prev-code code))
-
- (while (and (> 4 (length key)) (< index length))
-
- (setq code (cdr (assq (aref word index) soundex-alist))
- index (1+ index)
-
-
- key (concat key (if (or (null code) (string= code prev-code))
- ()
- code))
- prev-code code))
-
- (if (> 4 (length key))
- (substring (concat key "000") 0 4)
- key)))
- (provide 'soundex)
|