Metaphone Phonetic Hash Algorithm
Version 2 BETA TEST 3 (Released Dec 12, 2000)
For bug reports, please use sourceforge.
---------------================----------------
This is an algorithm expressed in Object Pascal to do the Metaphone phonetic hash. It's kind of like soundex, but a little more specific.
The original metaphone algorithm was implemented Lawrence Philips in Pick Basic. He can be reached by sending an email to lfp at dolby.com. There is a newer version of this algorithm, called "double metaphone". You can find out more about the metaphone algorithm by checking out the aspell metaphone page and at metaphone.net
The input to the algorithm is a word, and the output is a hash. If two hashes match, that means that the two original words sounded phonetically similar. An excellent technique for LESS sensitivity is to only compare the first few digits of the code as per Soundex.
All source code included in this ZIP file is coyrighted (c) 1996-1999 by White Computer Services. This package has been placed under the GNU LGPL license which is very much an open source license.
If anyone is interested in doing ANOTHER SPOKEN LANGUAGE version of this package please email me. I am very interested in adding multi- language support to this algorithm. Some languages would be more difficult than others, I suspect, and I will really need the help of somebody who speaks it fluently.
I also plan on porting this to other languages (most specifically Python) in the near future.
The component code was originally written by Rickard Dahlstrand, and has only been rearranged so that the actual algorithm is in another unit.
Thanks to Jason Wharton for providing the impetus to finally rewrite
this code into something more usable / stable. This algorithm will
be included with his IBObjects component suite. You should check it
out at:
http://www.ibobjects.com
You can reach me at:
email:
wcstom@yahoo.com
or
whitet@iname.com (redirect)
If you'd like help implementing this algorithm into your project, I'm
available at reasonable rates. Please contact me via email.
---------------================----------------
Version Information:
v1.1 Checks the length of the string before removing trailing S (must be >1) 'PH' used to translate to 'H' (incorrectly). It now translates to 'F'.
v1.2 The pairs at the beginning of the word were not being translated.
v1.3 The component had a bug - simple but deadly
v1.4 Fixed the code that checks the first two letters, added PS->S The input length is checked correctly.
v2.0B Complete rewrite of algorithm. Rules are put into constants so they can be easily changed. Please send comments/bug reports!
v2.0BR3 Fixed "Z" bug (sourceforge #111944)
---------------================----------------
****Docs for the metaphone component****
-----------------------------------------
Using the metaphone algorithm as a function call:
1. Add mtph2 to your uses clause.
2. Call it passing pchars (make sure the third arguement is large enough to hold the answer).
-----------------------------------------
Use as a DLL:
compile metaphon.dpr
>\progra~1\borland\delphi~1\bin\dcc32 metaphon.dpr
or use the IDE
Call from your
-----------------------------------------
Using the metaphone component:
Install: Add the file metaphon.pas into a package and recompile.
Files involved: metaphon.pas, mtph2.pas
Properties:
OutLength : Integer
Outlength will chop off the output metaphone string to be this many
characters or less, even if the input string would make a longer
metaphone string.
InString : String
InString is the input property for the component.
OutString : String
OutString is the output property for the component.
Methods:
Procedure Execute;
Translates whatever string is in the InString property into a
metaphone string of OutLength characters or less and places it
into the OutString property.
Procedure Metaphone(InStr : String; Length : integer; var Res : string);
This procedure is used if you don't want to go through the hassle of
setting InString, calling the Execute method and then reading the
Oustring property.
Also:
Probably the easiest way to use this component is not as a component at all: Change the word "Library" at the top of metaphon.dpr to the word "Unit", and save it as a .pas file.
Then in your code, just reference the file in your uses clause like this:
uses Windows, xxx, metaphon;