Brian Dunning's FileMaker Custom Functions

Soundex ( text )

MySQL's SOUNDEX() and the US Census Bureau's canonical American Soundex agree on H/W transparency and vowel-separation, but differ on one obscure rule: names where the first letter and second letter share the same code (like "Pfister", P=1/F=1). MySQL drops the F; the canonical spec also drops it — so no divergence there. The main thing to note in documentation is that this function matches MySQL's output, not the original Soundex patent, and non-ASCII characters are stripped silently.

  Be the first to rate this function Log in to vote

Joshua Paul   Joshua Paul - Show more from this author
Neo Code
http://www.neocode.com

  Sample input:
Soundex ( "Ashcraft" )
  Sample output:
A261

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

The script Name it: Soundex_Test
No parameters needed. Requires no fields, no layout context.

# ============================================================
# Soundex_Test
# Runs 14 test cases against the Soundex() custom function.
# No fields or layout required. Results in Show Custom Dialog.
# FM 21 (v21) compatible.
# ============================================================

# --- Define test cases as return-delimited lists ---

Set Variable [ $inputs ;
Value:
"Robert" & ¶ &
"Rupert" & ¶ &
"Rubin" & ¶ &
"Ashcraft" & ¶ &
"Pfister" & ¶ &
"Tymczak" & ¶ &
"Honeyman" & ¶ &
"Washington" & ¶ &
"A" & ¶ &
"" & ¶ &
"123 !@#" & ¶ &
"O'Brien" & ¶ &
"Lloyd" & ¶ &
"Jackson"
]

Set Variable [ $expected ;
Value:
"R163" & ¶ &
"R163" & ¶ &
"R150" & ¶ &
"A261" & ¶ &
"P236" & ¶ &
"T522" & ¶ &
"H555" & ¶ &
"W252" & ¶ &
"A000" & ¶ &
"" & ¶ &
"" & ¶ &
"O165" & ¶ &
"L300" & ¶ &
"J250"
]

# --- Initialise counters and accumulators ---

Set Variable [ $total ; Value: ValueCount ( $inputs ) ]
Set Variable [ $pass ; Value: 0 ]
Set Variable [ $fail ; Value: 0 ]
Set Variable [ $i ; Value: 1 ]
Set Variable [ $report ; Value: "" ]

# --- Loop through each test case ---

Loop
Exit Loop If [ $i > $total ]

Set Variable [ $input ; Value: GetValue ( $inputs ; $i ) ]
Set Variable [ $exp ; Value: GetValue ( $expected ; $i ) ]
Set Variable [ $got ; Value: Soundex ( $input ) ]

# Display empty string inputs as in the report
Set Variable [ $label ;
Value: If ( IsEmpty ( $input ) ; "" ; $input )
]

If [ $got = $exp ]
Set Variable [ $pass ; Value: $pass + 1 ]
Set Variable [ $status ; Value: "PASS" ]
Else
Set Variable [ $fail ; Value: $fail + 1 ]
Set Variable [ $status ; Value: "FAIL ← got "" & $got & "" expected "" & $exp & """ ]
End If

Set Variable [ $report ;
Value:
$report &
$status & " " &
$label & " → " &
$exp & ¶
]

Set Variable [ $i ; Value: $i + 1 ]

End Loop

# --- Build summary header ---

Set Variable [ $summary ;
Value:
"Soundex() test results — FM 21" & ¶ &
"=================================" & ¶ &
"Total: " & $total &
" Pass: " & $pass &
" Fail: " & $fail & ¶ &
"=================================" & ¶ &
$report
]

# --- Show results ---

Show Custom Dialog [
Title: "Soundex Test Runner" ;
Message: $summary ;
Buttons: "OK"
]

-------------------------------------------------------------------------
Soundex() test results — FM 21
=================================
Total: 14 Pass: 14 Fail: 0
=================================
PASS Robert → R163
PASS Rupert → R163
PASS Rubin → R150
PASS Ashcraft → A261
PASS Pfister → P236
PASS Tymczak → T522
PASS Honeyman → H555
PASS Washington → W252
PASS A → A000
PASS
PASS 123 !@# →
PASS O'Brien → O165
PASS Lloyd → L300
PASS Jackson → J250
---------------------------------------------------------------------------------
If a test fails it will look like:
FAIL ← got "T252" expected "T522" Tymczak → T522

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 22 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: