Sub topic 6
Exact, fuzzy, phonetic, and token-based name matching
This chapter assumes you have read the chapter on preparing names for comparison. You should know why names are normalized (lowercase, accents removed, punctuation stripped) before they are compared. You should also be able to read short Python programs. Here you will see four ways to compare two normalized names and learn where each one fails.
The working model
A screening engine compares a customer name with each listed name and produces a score. Usually the score runs from 0.0 (nothing in common) to 1.0 (identical). The next chapter covers the threshold that turns a score into an alert. This chapter covers how the score is produced.
No single technique is enough. Real engines combine several. Each one catches a different kind of difference between two spellings of the same person.
| Technique | What it catches | What it misses |
|---|---|---|
| Exact | Identical strings after normalization | Any spelling or order difference |
| Fuzzy | Typos, transliteration variants, small edits | Reordered parts, unrelated spellings of the same sound |
| Phonetic | Names that sound alike but are spelled differently | Names from other languages, very short names |
| Token-based | Reordered or missing name parts | Variants inside a single word, unless combined with fuzzy |
Exact matching
Exact matching checks whether two normalized strings are equal. It is fast and gives almost no noise. It is also the weakest control. "Mohammed Al-Sayed" and "Mohamed Al Sayed" differ by one letter, and an exact comparison will not link them. Use exact matching as a first, cheap pass, and never as the only one.
Fuzzy matching
Fuzzy matching measures how close two strings are. A common measure is edit distance, which counts the insertions, deletions, and substitutions needed to turn one string into the other. Python's difflib.SequenceMatcher returns a ratio between 0.0 and 1.0 based on the longest matching blocks of characters.
Fuzzy matching handles transliteration, the conversion of a name from one alphabet to another. Arabic, Cyrillic, and Chinese names have several accepted Latin spellings, such as "Mohammed", "Muhammad", and "Mohamed".
Phonetic matching
Phonetic algorithms reduce a name to a code based on how it sounds. Two names with the same code are treated as candidates. Soundex is the classic example. Double Metaphone is a more modern one that handles more spelling patterns. These algorithms were designed mostly around English pronunciation, so they work less well on names from other languages. Treat a phonetic hit as a reason to look closer, not as proof.
Token-based matching
A token is one word of a name. Token-based matching compares names word by word instead of as one long string. This helps because name order varies. A list may hold "Sayed, Mohamed Al" while your customer record holds "Mohamed Al Sayed". One approach is token sorting: sort the words alphabetically, rejoin them, and then compare. Another is token set comparison, which scores the overlap and tolerates a missing middle name.
A worked example
The program below normalizes both names, sorts the tokens, and applies a fuzzy ratio. It also shows an exact comparison on the same pair.
import re
import unicodedata
from difflib import SequenceMatcher
def normalize(name: str) -> str:
decomposed = unicodedata.normalize("NFKD", name)
no_accents = "".join(c for c in decomposed if not unicodedata.combining(c))
no_punct = re.sub(r"[^\w\s]", " ", no_accents.casefold())
return " ".join(no_punct.split())
def exact(a: str, b: str) -> bool:
return normalize(a) == normalize(b)
def token_sort_score(a: str, b: str) -> float:
ta = " ".join(sorted(normalize(a).split()))
tb = " ".join(sorted(normalize(b).split()))
return SequenceMatcher(None, ta, tb).ratio()
customer = "Mohammed Al-Sayed"
listed = "Al Sayed, Mohamed"
print(exact(customer, listed))
print(round(token_sort_score(customer, listed), 2))
print(round(token_sort_score(customer, "Jane Doe"), 2))The exact check returns False, because of the reordering and the extra "m". The token-sort score is high, because the sorted words differ by a single letter. The unrelated name scores low. This is the pattern you want: close variants score high and unrelated names score low.
Common errors
- Using one technique alone. Exact matching misses variants. Fuzzy matching alone misses reordered names. Combine them.
- Fuzzy scores on very short names. One edit in a four-letter name changes the ratio a lot, so short names produce unstable scores.
- Treating a phonetic hit as a match. Many unrelated names share a code. A phonetic hit is only a candidate.
- Skipping normalization. Accents, case, and punctuation lower scores for no good reason.
- Ignoring the cost of a miss. A tool that is easy to run but misses variants leaves the firm exposed.
Exercise
Exercise
A customer is recorded as "Sayed Mohamed Al" and a listed party as "Mohammed Al-Sayed". Which two techniques from this chapter would most likely link them, and why would an exact match fail?
Show answer
Token-based matching (sorting or comparing words, which handles the different order) combined with fuzzy matching (which handles the "Mohamed" and "Mohammed" spelling difference). An exact match fails because, even after normalization, the word order differs and one name has an extra "m", so the strings are not equal.
Exercise
Why should a phonetic match alone not be treated as a confirmed match?
Show answer
Phonetic codes group names that merely sound alike, so many unrelated people share the same code. Phonetic algorithms also fit English pronunciation better than other languages. A phonetic hit is a candidate that needs a closer score and secondary identifiers.