473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Metaphone source code

A97

I have found a number of e-mails in the archives referring to the
above, but have yet to find it. If anyone has gone through the
routine of coding the above, would they be happy to share it with me?

Thanks for reading and merry Xmas

Mark McCall
Market Research Analyst - Data
National Blood Service
Nov 12 '05 #1
1 7194
rkc

"Mark McCall" <ma*********@nbs.nhs.uk> wrote in message
news:22**************************@posting.google.c om...
A97

I have found a number of e-mails in the archives referring to the
above, but have yet to find it. If anyone has gone through the
routine of coding the above, would they be happy to share it with me?


I just ran accross this when I was purging some old junk from
one of my purloined source code folders. I don't think I ever
actually tried this out, but here it is any way.

'Metaphone algorithm translated from C to Delphi by Tom White
<wc*@intellex.com>
'Translated to Visual Basic by Dave White 9/10/01
'
'v1.1 fixes a few bugs
'
' Checks length of string before removing trailing S (>1)
' PH used to translate to H, now translates to F

'Original C version by Michael Kuhn <rh*********@uunet.uu.net>
'
'

Function InStrC (ByVal SearchIn As String, ByVal SoughtCharacters As String)
As Integer
'--- Returns the position of the first character in SearchIn that is
contained
'--- in the string SoughtCharacters. Returns 0 if none found.
Dim i As Integer

On Error Resume Next
SoughtCharacters = UCase(SoughtCharacters)
SearchIn = UCase(SearchIn)
For i = 1 To Len(SearchIn)
If InStr(SoughtCharacters, Mid(SearchIn, i, 1)) > 0 Then
InStrC = i: Exit Function
End If
Next i
InStrC = 0
End Function

Function Metaphone (ByVal A As Variant) As String
Dim b, c, d, e As String
Dim inp, outp As String
Dim vowels, frontv, varson, dbl As String
Dim excppair, nxtltr As String
Dim T, ii, jj, lng, lastchr As Integer
Dim curltr, prevltr, nextltr, nextltr2, nextltr3 As String
Dim vowelafter, vowelbefore, frontvafter, silent, hard As Integer
Dim alphachr As String

On Error Resume Next
If IsNull(A) Then A = ""
A = CStr(A)
inp = UCase(A)
vowels = "AEIOU"
frontv = "EIY"
varson = "CSPTG"
dbl = "." 'Lets us allow certain letters to be doubled
excppair = "AGKPW"
nxtltr = "ENNNR"
alphachr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

'--Remove non-alpha characters
outp = ""
For T = 1 To Len(inp)
If InStr(alphachr, Mid(inp, T, 1)) > 0 Then outp = outp + Mid(inp, T, 1)
Next T

inp = outp: outp = ""

If Len(inp) = 0 Then Metaphone = "": Exit Function

'--Check rules at beginning of word
If Len(inp) > 1 Then
b = Mid(inp, 1, 1)
c = Mid(inp, 2, 1)
ii = InStr(excppair, b)
jj = InStr(nxtltr, c)
If ii = jj And ii > 0 Then
inp = Mid(inp, 2, Len(inp) - 1)
End If
End If

If Mid(inp, 1, 1) = "X" Then Mid(inp, 1, 1) = "S"

If Mid(inp, 1, 2) = "WH" Then inp = "W" + Mid(inp, 3)

If Right(inp, 1) = "S" Then inp = Left(inp, Len(inp) - 1)

ii = 0
Do
ii = ii + 1
'--Main Loop!
silent = False
hard = False
curltr = Mid(inp, ii, 1)
vowelbefore = False
prevltr = " "
If ii > 1 Then
prevltr = Mid(inp, ii - 1, 1)
If InStrC(prevltr, vowels) > 0 Then vowelbefore = True
End If

If ((ii = 1) And (InStrC(curltr, vowels) > 0)) Then
outp = outp + curltr
GoTo ContinueMainLoop
End If

vowelafter = False
frontvafter = False
nextltr = " "
If ii < Len(inp) Then
nextltr = Mid(inp, ii + 1, 1)
If InStrC(nextltr, vowels) > 0 Then vowelafter = True
If InStrC(nextltr, frontv) > 0 Then frontvafter = True
End If

'--Skip double letters EXCEPT ones in variable double
If InStrC(curltr, dbl) = 0 Then
If curltr = nextltr Then GoTo ContinueMainLoop
End If

nextltr2 = " "
If Len(inp) - ii > 1 Then
nextltr2 = Mid(inp, ii + 2, 1)
End If

nextltr3 = " "
If (Len(inp) - ii) > 2 Then
nextltr3 = Mid(inp, ii + 3, 1)
End If

Select Case curltr
Case "B":
silent = False
If (ii = Len(inp)) And (prevltr = "M") Then silent = True
If Not (silent) Then outp = outp + curltr
Case "C":
If Not ((ii > 2) And (prevltr = "S") And frontvafter) Then
If ((ii > 1) And (nextltr = "I") And (nextltr2 = "A")) Then
outp = outp + "X"
Else
If frontvafter Then
outp = outp + "S"
Else
If ((ii > 2) And (prevltr = "S") And (nextltr = "H"))
Then
outp = outp + "K"
Else
If nextltr = "H" Then
If ((ii = 1) And (InStrC(nextltr2, vowels) = 0))
Then
outp = outp + "K"
Else
outp = outp + "X"
End If
Else
If prevltr = "C" Then
outp = outp + "C"
Else
outp = outp + "K"
End If
End If
End If
End If
End If
End If
Case "D":
If ((nextltr = "G") And (InStrC(nextltr2, frontv) > 0)) Then
outp = outp + "J"
Else
outp = outp + "T"
End If

Case "G":
silent = False
If ((ii < Len(inp)) And (nextltr = "H") And (InStrC(nextltr2,
vowels) = 0)) Then
silent = True
End If
If ((ii = Len(inp) - 4) And (nextltr = "N") And (nextltr2 =
"E") And (nextltr3 = "D")) Then
silent = True
ElseIf ((ii = Len(inp) - 2) And (nextltr = "N")) Then
silent = True
End If
If (prevltr = "D") And frontvafter Then silent = True
If prevltr = "G" Then
hard = True
End If

If Not (silent) Then
If frontvafter And (Not (hard)) Then
outp = outp + "J"
Else
outp = outp + "K"
End If
End If

Case "H":
silent = False
If InStrC(prevltr, varson) > 0 Then silent = True
If vowelbefore And (Not (vowelafter)) Then silent = True
If Not silent Then outp = outp + curltr

Case "F", "J", "L", "M", "N", "R": outp = outp + curltr

Case "K": If prevltr <> "C" Then outp = outp + curltr

Case "P": If nextltr = "H" Then outp = outp + "F" Else outp = outp + "P"

Case "Q": outp = outp + "K"

Case "S":
If ((ii > 2) And (nextltr = "I") And ((nextltr2 = "O") Or
(nextltr2 = "A"))) Then
outp = outp + "X"
End If
If (nextltr = "H") Then
outp = outp + "X"
Else
outp = outp + "S"
End If

Case "T":
If ((ii > 0) And (nextltr = "I") And ((nextltr2 = "O") Or
(nextltr2 = "A"))) Then
outp = outp + "X"
End If
If nextltr = "H" Then
If ((ii > 1) Or (InStrC(nextltr2, vowels) > 0)) Then
outp = outp + "0"
Else
outp = outp + "T"
End If
ElseIf Not ((ii < Len(inp) - 3) And (nextltr = "C") And
(nextltr2 = "H")) Then
outp = outp + "T"
End If

Case "V": outp = outp + "F"

Case "W", "Y": If (ii < Len(inp) - 1) And vowelafter Then outp = outp +
curltr

Case "X": outp = outp + "KS"

Case "Z": outp = outp + "S"

End Select
ContinueMainLoop:
Loop Until (ii > Len(inp))

Metaphone = outp

End Function

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fartsniff | last post by:
hey all, i am currently using a search engine on my site that compares values stored in the meta tags with what the user types in. any matches return the "title" of the page, a thumbnail and a...
1
by: willl69 | last post by:
Hi Guys, I have been writing a database search for my site, to increase the accuracy and chance of a successful resut i have used the metaphone() and similar_text() comparisons to find the...
9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
3
by: JohnH | last post by:
I'm very interested in implementing double-metaphone search in my database to resolve customer names, and I've done quite a bit of searching trying to find a VBA implementation. I know that Clive...
3
by: rashpal.sidhu | last post by:
Please help, this problem is driving me crazy !! I am using metaphone to create phonetic keys. When i run the module stand-a-lone it works fine. I'm trying to create a runner for informix...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
0
by: okonita | last post by:
Hi all, I am in need of examples of a UDF scalar function that can call a Java or C++ routine to return the DoubleMetaphone keys for a name/word search or something like that. I have never written...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.