Link node keeps names as written; compares them normalised
This commit is contained in:
+9
-5
@@ -229,13 +229,14 @@ def _near(identifier: str) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def _identities(p: str, node: Link) -> tuple[pd.DataFrame, dict[str, str]]:
|
||||
def _identities(p: str, node: Link) -> tuple[pd.DataFrame, dict[str, str], dict[str, str]]:
|
||||
"""One row per record: its identity fields (first value found, reviewers' corrections
|
||||
applied, identifiers plain); records rejected for identity are left out. And the input
|
||||
each record came through (its record number's system)."""
|
||||
each record came through (its record number's system), and its name as written."""
|
||||
skip, fixed = nodes.rejected("identity"), nodes.corrections()
|
||||
records: dict[str, dict] = {}
|
||||
sources: dict[str, str] = {}
|
||||
written: dict[str, str] = {} # each record's name as it came (compared normalised)
|
||||
for i in node.inputs:
|
||||
for row in nodes.rows(p, i):
|
||||
if row.get(HELD) or row[RECORD] in skip:
|
||||
@@ -246,13 +247,15 @@ def _identities(p: str, node: Link) -> tuple[pd.DataFrame, dict[str, str]]:
|
||||
for f in node.fields:
|
||||
if row.get(f) is not None and mine.get(f) is None:
|
||||
value = str(row[f])
|
||||
if f == "full_name":
|
||||
written[row[RECORD]] = " ".join(value.split())
|
||||
mine[f] = (
|
||||
_plain(value) if f in IDENTIFIERS
|
||||
else _name(value) if f == "full_name" else value
|
||||
) # fmt: skip
|
||||
frame = pd.DataFrame(list(records.values()))
|
||||
present = [f for f in node.fields if f in frame and frame[f].notna().any()]
|
||||
return frame[["unique_id", *present]], sources
|
||||
return frame[["unique_id", *present]], sources, written
|
||||
|
||||
|
||||
def _persons(records: pd.DataFrame, edges: pd.DataFrame, db: DuckDBAPI) -> pd.DataFrame:
|
||||
@@ -267,7 +270,7 @@ def run_link(p: str, node: Link):
|
||||
apart by reviewers' decisions. A person whose records disagree on birth date or sex is
|
||||
held. Persons that may be one (identifiers one typo apart, or the same birth date) and
|
||||
don't contradict each other are queued for review, with Splink's probability."""
|
||||
records, sources = _identities(p, node)
|
||||
records, sources, written = _identities(p, node)
|
||||
fields = [c for c in records.columns if c != "unique_id"]
|
||||
rules = [r for r in node.rules or node.default_rules()
|
||||
if all(f"l.{f}" not in r or f in fields for f in node.fields)] # fmt: skip
|
||||
@@ -298,7 +301,8 @@ def run_link(p: str, node: Link):
|
||||
linked = [
|
||||
{RECORD: r.unique_id, "person_id": stable[r.cluster_id], "_source": sources[r.unique_id],
|
||||
HELD: held if r.cluster_id in torn else None,
|
||||
**{f: getattr(r, f) for f in fields}}
|
||||
**{f: getattr(r, f) for f in fields},
|
||||
**({"full_name": written[r.unique_id]} if r.unique_id in written else {})}
|
||||
for r in persons.itertuples()
|
||||
] # fmt: skip
|
||||
nodes.write(p, node.id, linked, columns)
|
||||
|
||||
@@ -47,6 +47,14 @@ def test_a_messy_site_becomes_silver_and_review_gets_the_rest(platform, messy_si
|
||||
assert torn and torn == held, (torn, held)
|
||||
patient = {p: next(iter(who)) for p, who in members.items() if p not in torn}
|
||||
|
||||
# A name reaches silver as the registry wrote it (accents, ñ); linking compared it
|
||||
# without them, so the reports' plain upper-case names still joined.
|
||||
torn_patients = {x for p in torn for x in members[p]}
|
||||
written = {r["values"]["full_name"] for r in truth
|
||||
if r["entity"] == "identity" and r["person"] not in torn_patients} # fmt: skip
|
||||
names = {text for (text,) in q("select text from silver.person_name")}
|
||||
assert any("ñ" in n for n in written) and written <= names
|
||||
|
||||
# Every patient split into several persons is in the review queue, joined by candidates.
|
||||
parts: dict[str, set] = {}
|
||||
for p, x in patient.items():
|
||||
|
||||
Reference in New Issue
Block a user