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)
|
||||
|
||||
Reference in New Issue
Block a user