Skip to main content

Phonetic Algorithms

Phonetic algorithms encode strings based on how they sound rather than how they are spelled. Two names with different spellings but similar pronunciation will produce the same (or similar) phonetic code, making these algorithms essential for name matching and deduplication.

All functions are imported directly from reclink.

from reclink import soundex, metaphone, double_metaphone

Overview

AlgorithmOriginCode formatBest for
SoundexUS Census (1880s)1 letter + 3 digits (e.g., S530)English surnames
MetaphoneLawrence Philips (1990)Variable-length consonant codeGeneral English
Double MetaphoneLawrence Philips (2000)Two codes (primary + alternate)Multi-origin English names
NYSIISNY State (1970)Up to 6 charactersAmerican names
CaverphoneNZ Govt (2002)10-character codeNZ/AU English names
Cologne PhoneticHans Postel (1969)Numeric codeGerman names and words
Beider-MorseStephen Morse (2008)|-separated variantsMulti-ethnic name matching
PhonexA.J. Lait & B. Randell1 letter + 3 digitsImproved Soundex with prefix handling
MRAWestern Airlines (1977)Up to 6 consonantsQuick name comparison
Daitch-MokotoffGary Mokotoff (1985)6-digit numeric (multi-valued)Slavic/Germanic/Hebrew names

soundex(s)

The original American Soundex algorithm. Returns a 4-character code consisting of an uppercase letter followed by three digits.

from reclink import soundex

soundex("Smith") # "S530"
soundex("Smyth") # "S530" -- same code
soundex("Robert") # "R163"
soundex("Rupert") # "R163" -- same code
soundex("Ashcraft") # "A261"
soundex("") # "0000"

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

str -- a 4-character Soundex code.


metaphone(s)

Produces a variable-length phonetic code using more refined rules than Soundex. Handles common English letter combinations (e.g., ph -> F, ght -> T).

from reclink import metaphone

metaphone("Smith") # "SM0"
metaphone("Schmidt") # "SXMTT"
metaphone("Phone") # "FN"
metaphone("Knight") # "NT"

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

str -- variable-length Metaphone code.


double_metaphone(s)

An improved version of Metaphone that returns two codes: a primary code and an alternate code. The alternate captures secondary pronunciations common in names of non-English origin.

from reclink import double_metaphone

double_metaphone("John") # ("JN", "AN")
double_metaphone("Smith") # ("SM0", "XMT")
double_metaphone("Schmidt") # ("XMTT", "SMTT")
double_metaphone("Catherine") # ("K0RN", "KTRN")

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

tuple[str, str] -- (primary_code, alternate_code). When there is no meaningful alternate, the second element may equal the first.


nysiis(s)

New York State Identification and Intelligence System. Returns an alphabetic code of up to 6 characters. More accurate than Soundex for American names.

from reclink import nysiis

nysiis("Macintosh") # "MCANT"
nysiis("Mcknight") # "MCNAG"
nysiis("Johnson") # "JANSAN"
nysiis("Jonson") # "JANSAN" -- same code

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

str -- up to 6 alphabetic characters.


caverphone(s)

Developed for the Caversham Project (New Zealand). Produces a 10-character code optimized for New Zealand and Australian English names.

from reclink import caverphone

caverphone("Thompson") # "TMSN111111"
caverphone("Thomson") # "TMSN111111" -- same code
caverphone("Lee") # "L111111111"
caverphone("Li") # "L111111111" -- same code

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

str -- 10-character Caverphone code.


cologne_phonetic(s)

Also known as the "Kolner Phonetik." Designed specifically for the German language. Returns a purely numeric code.

from reclink import cologne_phonetic

cologne_phonetic("Muller") # "657"
cologne_phonetic("Mueller") # "657" -- same code
cologne_phonetic("Muller") # "657"
cologne_phonetic("Breschnew") # "17863"

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode

Returns

str -- variable-length numeric code.


beider_morse(s, ashkenazi=False)

The Beider-Morse Phonetic Matching algorithm. Designed for matching names across multiple languages and ethnicities. Returns multiple possible phonetic encodings separated by |.

from reclink import beider_morse

beider_morse("Schwartz") # "svarts|zvarts|..."
beider_morse("Cohen") # "koen|kYn|..."
beider_morse("Cohen", ashkenazi=True) # Ashkenazi-specific rules

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to encode
ashkenaziboolFalseWhen True, use Ashkenazi-specific phonetic rules

Returns

str -- |-separated phonetic variants.


detect_language(s)

Detects the likely language of a string based on character analysis. Useful for selecting the appropriate phonetic algorithm or preprocessing pipeline.

from reclink import detect_language

detect_language("Mueller") # "german"
detect_language("Smith") # "english"
detect_language("Ivanov") # "russian"

Parameters

ParameterTypeDefaultDescription
sstrrequiredInput string to analyze

Returns

str -- detected language name (lowercase).


phonetic_hybrid(a, b, phonetic="soundex", metric="jaro_winkler", phonetic_weight=0.3)

Combines a string similarity metric with a phonetic comparison into a single blended score. The formula is:

score = (1 - phonetic_weight) * metric(a, b) + phonetic_weight * metric(phonetic(a), phonetic(b))

This is particularly useful when names may be spelled differently but sound alike.

from reclink import phonetic_hybrid

# Default: 70% Jaro-Winkler + 30% Soundex-based Jaro-Winkler
phonetic_hybrid("Smith", "Smyth") # high score (same Soundex)
phonetic_hybrid("Robert", "Rupert") # boosted by shared Soundex code

# German names with Cologne Phonetic
phonetic_hybrid(
"Mueller", "Muller",
phonetic="cologne_phonetic",
metric="jaro_winkler",
phonetic_weight=0.5,
)

# Multi-ethnic matching with Beider-Morse
phonetic_hybrid(
"Schwartz", "Svarts",
phonetic="beider_morse",
metric="levenshtein_similarity",
phonetic_weight=0.4,
)

Parameters

ParameterTypeDefaultDescription
astrrequiredFirst string
bstrrequiredSecond string
phoneticstr"soundex"Phonetic algorithm to use. One of: "soundex", "metaphone", "double_metaphone", "nysiis", "caverphone", "cologne_phonetic", "beider_morse"
metricstr"jaro_winkler"String similarity metric to apply to both raw and phonetic strings
phonetic_weightfloat0.3Weight given to the phonetic component. Must be in [0, 1].

Returns

float in [0, 1].


Choosing the Right Algorithm

ScenarioRecommended algorithm
English surnamessoundex or double_metaphone
General English wordsmetaphone
Names with multiple possible originsdouble_metaphone or beider_morse
German namescologne_phonetic
New Zealand / Australian namescaverphone
American names (government records)nysiis
Multi-ethnic datasetsbeider_morse
Unsure / mixed dataphonetic_hybrid with double_metaphone

Phonex

Improved variant of Soundex with better prefix handling (KN→N, WR→R, PH→F) and phoneme groupings.

from reclink import phonex

phonex("Smith") # "S530"
phonex("Knight") # "N230" (K dropped)
phonex("Wright") # "R230" (W dropped)

Match Rating Approach (MRA)

Two-part algorithm: encodes names by stripping vowels and compressing duplicates, then compares codes using a minimum-rating threshold.

from reclink import mra, mra_compare

mra("Smith") # "SMTH"
mra("Catherine") # "CTHRN"

mra_compare("Smith", "Smyth") # True
mra_compare("Smith", "Jones") # False

Daitch-Mokotoff Soundex

6-digit numeric codes for Slavic, Germanic, and Hebrew surnames. Can produce multiple codes when rules are ambiguous (branching).

from reclink import daitch_mokotoff

daitch_mokotoff("Schwartz") # "479400"
daitch_mokotoff("Cohen") # "560000"
daitch_mokotoff("Chaim") # "560000,460000" (branching)

Edge Cases

  • Empty strings return an empty code (or "0000" for Soundex/Phonex, "000000" for Daitch-Mokotoff).
  • Non-alphabetic characters are generally ignored.
  • Unicode characters are handled by transliteration where applicable (e.g., cologne_phonetic handles German umlauts).

See Also

  • String Metrics -- all distance and similarity functions
  • Preprocessing -- transliterate_cyrillic, transliterate_greek, and other transliteration functions
  • Batch Operations -- phonetic_batch_arrow for encoding entire columns at once
  • Concepts -- conceptual overview of phonetic matching