LVG Metaphone Algorithm
Introduction:
The Lexical tool uses the "Metaphone" phonetic code algorithm by Lawrence Philips, "Hanging on the Metaphone", Computer Language v7n12, December 1990, pp. 39-43. An input term is reduced to a 1 to 6 character code (configurable) using relatively simple phonetic rules for typical spoken English.
Basically, Metaphone reduces the alphabet to 16 consonant sounds:
B F H J K L M N P R S T W X Y 0 (zero)
where the 0 (zero) represents the 'th' sound.
Input
- inStr: an input string.
- maxCodeLength: the length for the transformed code to be truncated.
Output: an output code in uppercased string.
Algorithm:
I. Pre-Process
Steps Descriptions | Conditions (if) | Actions (then)
|
Initial check
| - inStr is null
- length of inStr == 0
|
|
Drop non-alphabetic characters
| - not an alphabetic character
|
|
Quick checki
| - length of current string is 0
|
|
Quick check
| - length of current string is 1
|
|
Uppercased
| |
|
II. Initial Letter Exceptions
III. Transformation by looping through the string
Steps Descriptions | Conditions (if) | Actions (then)
|
Doubled letters rules
| - doubled letter && is not C
|
|
Vowel Letters Rules
| - is not the first letter C
|
|
B Rules
| - at the end of the word && after M (MB)
|
|
C Rules-I
| - before IA (CIA)
- before H && not after S (CH, not SCH)
|
|
C Rules-II
| - before FrontV (CE, CI, CY)
| C Rules-III
| - other than above two C rules
|
| D Rules-I
| - before G plus FrontV (DGE, DGI, DGY)
|
| D Rules-II
|
|
| G Rules-I
| - before N (GN)
- before NED (GNED)
- after D && before FrontV (DGE, DGI, DGY)
- before H (GH) && ((at the end) || (before a Consonant))
|
| G Rules-II
| - before FrontV (GE, GI, GY)
|
| G Rules-III
|
|
| H Rules-I
| - after Vowel
- after Varson
- before consonant (not vowels)
|
| H Rules-II
|
|
| K Rules-I
|
|
| K Rules-II
|
|
| P Rules-I
|
|
| P Rules-II
|
|
| Q Rules
|
|
| S Rules-I
| - before H (SH)
- before IA (SIA)
- before IO (SIO)
|
| S Rules-II
|
|
| T Rules-I
| - before IA (TIA)
- before IO (TIO)
|
| T Rules-II
|
|
| T Rules-III
|
|
| T Rules-IV
|
|
| V Rules
|
|
| W Rules-I
| - before Consonant (not vowels)
|
| W Rules-II
|
|
| X Rules
|
|
| Y Rules-I
| - before Consonant (not vowels)
|
| Y Rules-II
|
|
| Z Rules
|
|
| defaults
| - all other cases (F, J, L, M, N, R, ...)
|
|
|
- Vowels: A, E, I, O, U
- FrontV: E, I, Y
- Varson: C, G, P, S, T
References