account-name-key-builder
Crystal command line tool and library. Give it a CSV of account ids and names and it builds a plain match key for each name, then lists the groups of rows that share a key, so you can see possible duplicate accounts in a list. The key rule, applied in this exact order: (1) lowercase; (2) "&" becomes " and "; (3) every character that is not a to z or 0 to 9 becomes a space, so accented letters are dropped, not transliterated ("Café" becomes "caf"); (4) collapse spaces; (5) remove a leading word "the"; (6) repeatedly remove a trailing word that is in the suffix list. The default suffix list is inc, incorporated, llc, ltd, limited, gmbh, corp, corporation, co, company, plc, pte, bv, ag, sa. The list is set by you: --suffixes a,b,c replaces it as a whole (entries are trimmed, lowercased and may use a to z and 0 to 9 only). Output: rows, distinct keys, rows sharing a key with another row, the number of groups with more than one row, and the first 10 of those groups by size (largest first, then key), each listing the account ids and the original names in input order. The key only helps you see possible duplicates. The tool merges nothing, does not look at addresses, domains or any other field, and two different companies can share a key.
Part of the OneGTMLab free GTM tools. Background on the idea: Clay.
Install
shards build # then ./bin/account-name-key-builder
Use
Input: CSV with the columns account_id and name, any order, header case does not matter. A cell may be double quoted (needed when a name holds a comma, as in "Alpha Widgets, LLC"). Line breaks inside a name are shown as one space. A name made only of a leading "the", suffix words or symbols leaves an empty key and stops the run, naming the row (the header counts as row 1). So do an empty name, an empty or duplicate account_id (compared after trimming, case matters), a missing column, an empty --suffixes, an unknown option, an empty file, a file with no data rows and a missing file: each prints a message and exits 1. In the example, the last two names show the quirk of step 3: "Zeta Café Ltd" and "Zeta Caf Inc" end up with the same key.
$ bin/account-name-key-builder sample.csv
rows: 11
distinct keys: 6
rows sharing a key with another row: 9
groups with more than one row: 4
suffix list: inc, incorporated, llc, ltd, limited, gmbh, corp, corporation, co, company, plc, pte, bv, ag, sa
groups (size, then key)
key: alpha widgets (3 rows)
A-1 Alpha Widgets Inc
A-2 Alpha Widgets, LLC
A-3 The Alpha Widgets Company
key: beta and sons (2 rows)
A-4 Beta & Sons Ltd
A-5 Beta and Sons Limited
key: gamma labs (2 rows)
A-6 Gamma Labs
A-7 Gamma Labs GmbH
key: zeta caf (2 rows)
A-10 Zeta Café Ltd
A-11 Zeta Caf Inc
Test
crystal spec
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.