Skip to content

Find the same company in two lists

At the end, you have the pairs that name the same company in one file, and the pairs ThinkThen is not sure about in another for a person.

Build the pairs with ordinary code first, such as entries that share a city or a postcode. Each pair is one question, so asking about every possible pair costs far more.

Write one pair per line, with both sides under one field, pair, so the model reads them together:

pairs.jsonl
{"id":"p1","pair":{"left":"Example Group Ltd, 12 High St, Leeds","right":"Example Grp, 12 High Street, Leeds"}}
{"id":"p2","pair":{"left":"Example Group Ltd, 12 High St, Leeds","right":"Sample Holdings, 4 Mill Lane, York"}}
{"id":"p3","pair":{"left":"Northwind Traders, Seattle","right":"Northwind, Seattle WA"}}
{"id":"p4","pair":{"left":"Contoso Ltd, Paris","right":"Contoso Group, Lyon"}}

2. Ask whether each pair names the same company

Section titled “2. Ask whether each pair names the same company”

--field /pair sends both sides as one text. The low and high bars send an unclear pair to not sure, and --into same adds the answer to each line:

Terminal window
thinkthen decide --field /pair --low 0.2 --high 0.8 \
--into same 'Do left and right name the same company?' \
pairs.jsonl > matched.jsonl
jq -c '{id, same}' matched.jsonl

Output

{"id":"p1","same":true}
{"id":"p2","same":false}
{"id":"p3","same":true}
{"id":"p4","same":"unsure"}

The first and third pairs spell one company two ways. The second names two companies. The fourth shares a name but not a city, so the model is not sure.

3. Keep the matches and set aside the unclear pairs

Section titled “3. Keep the matches and set aside the unclear pairs”

same.jsonl gets the matches, ready to join. person.jsonl gets the not-sure and failed pairs:

Terminal window
jq -c 'select(.same == true) | .pair' matched.jsonl \
> same.jsonl
jq -c 'select(.same == null or .same == "unsure") | .pair' \
matched.jsonl > person.jsonl
cat person.jsonl

Output

{"left":"Contoso Ltd, Paris","right":"Contoso Group, Lyon"}

The Contoso pair is the one a person decides. Never count a not-sure or failed pair as a match or a non-match by default.

  • Label a sample of pairs yourself and compare, as Measure answers against your own labels shows.
  • A wrong yes merges two different companies. If you find one, widen the gap between the bars, so more pairs go to a person.

Break a problem into decisions shows how to split a larger job into questions like this one.