Write up a prediction-ready entity reconciliation system for us on your personal computer.
Implement reconcile_entities(records, threshold). Each record is a dictionary containing record_id, name, email, and phone, where values may be empty strings. Return sorted dictionaries with canonical_id, sorted members, and a confidence score. Normalize text case-insensitively and remove non-alphanumeric characters. Use candidate blocking, weighted comparison, and transitive clustering. Two records may be compared only when they share a normalized email, phone, or first-four-character name block. Their score is 0.5 for equal nonempty emails, 0.3 for equal nonempty phones, and 0.2 * SequenceMatcher name similarity. Join records when the score meets threshold, unless two populated identifiers conflict. The canonical record has the most populated fields, with record_id as the tie-breaker.
def reconcile_entities(records, threshold):