Almost the Same Customer
After a CRM import your customer master is littered with near-duplicates: "Nordwind Handelskontor GmbH" sits next to "Nordwind Handelsokntor", and "ACME industrial holdings Ltd." next to "Acme Industrial Holdings GmbH & Co. KG". You are building the matching engine that finds these pairs — a normalization pre-pass, a typo-aware edit distance, and a pair scan that survives a 300-row candidate list without comparing everything against everything.
Requirements
The starter includes two tables that the tests bind to — submit them unchanged:
- table
"Name Match Candidate":"Entry No."(Integer, primary key),Name(Text[100]); - table
"Name Match Pair":"Entry No. 1","Entry No. 2"(Integer, composite primary key),Similarity(Decimal).
Create a codeunit named "Fuzzy Customer Match" with five public procedures:
procedure NormalizeName(Name: Text): Text
procedure EditDistance(Left: Text; Right: Text): Integer
procedure Similarity(NameA: Text; NameB: Text): Decimal
procedure FindDuplicates(var Candidate: Record "Name Match Candidate"; Threshold: Decimal; var MatchPair: Record "Name Match Pair")
procedure GetScoredPairCount(): IntegerNormalizeName
Apply these steps in order:
- Uppercase the whole name.
- Replace every character that is not
A–Zor0–9with a space (this includes punctuation like.,,,&,-,'). - Collapse every run of spaces into a single space and trim leading and trailing spaces, so the result is space-separated words.
- While the name still has at least two words and its last word is one of the legal-form words
AG,APS,BV,CO,CORP,GMBH,INC,KG,LLC,LTD,OY,PLC,SA,SARL, drop that last word — repeatedly, so"Acme GmbH & Co. KG"becomes"ACME"one word at a time.
Legal-form words anywhere else stay: "Ltd Tools Ltd" normalizes to "LTD TOOLS", and a name that consists of nothing but a single legal-form word stays as itself ("GmbH" → "GMBH").
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 13 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in