Skip to content

Instantly share code, notes, and snippets.

@Rostepher
Last active June 5, 2023 13:09
Show Gist options
  • Save Rostepher/b688f709587ac145a0b3 to your computer and use it in GitHub Desktop.
Save Rostepher/b688f709587ac145a0b3 to your computer and use it in GitHub Desktop.
Metaphone algorithm explaination.

The Metaphone algorithm was Created by Lawrence Philips. The Metaphone algorithm was first introduced in an article published in "Computer Language" December 1990 issue. Since its inception the algorithm has been updated by the original author, Lawrence Phillips, twice. The second iteration, released in 2000 was the Double Metaphone and the most recent update is the Metaphone 3, realease in 2009 under a proprietary license and as such is unavailable without a purchased license.

Consonant Sounds

There are 16 distinct "consonant sounds" in the metaphone algorithm. B, F, H, J, K, L, M, N, O, P, R, S, T, W, X, Y and 0 (zero) where 0 represents the th sound.

Transformations (Steps)

  1. Drop duplicate adjacent letters, except for C
  2. Drop the first letter if the string begins with AE, GN, KN, PN or WR
  3. Drop B if after M at the end of the string
  4. C transforms into
    • X if followed by IA or H
    • S if followed by I, E, or Y
    • K otherwise
  5. D transforms into
    • J if followed by GE, GY, or GI
    • T otherwise
  6. Drop G
    • if followed by H and H is not at the end or before a vowel
    • if followed byN or NED and is at the end of the string
  7. G transforms into
    • J if before I, E or Y and is not a GG
    • K otherwise
  8. Drop H
    • if after a vowel and not before a vowel
    • if after C, S, P, T or G
  9. Drop K if after C
  10. PH transforms into F
  11. Q transforms into K
  12. S transforms into X if followed by H, IO or IA
  13. T transforms into X if followed by IA or IO
  14. TH transforms into 0 (zero)
  15. Drop T if followed by CH
  16. V transforms into F
  17. Drop W if not followed by a vowel
  18. WH transforms into W if at the beginning of the string
  19. X transforms into
    • S if at the beginning
    • KS otherwise
  20. Drop Y if not followed by a vowel
  21. Z transforms into S
  22. Drop all vowels unless it is the beginning character

Links

  1. Original BASIC Implementation
  2. C Implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment