A reviewer's answer holds when more records join a person
This commit is contained in:
+4
-1
@@ -425,6 +425,9 @@ def run_link(p: str, node: Link):
|
||||
orphan = set(whole.unique_id[whole[facts].isna().all(axis=1)]) if facts else set()
|
||||
# no birth date to tell her apart (a pathology scan: a name, misread or not, and a sex)
|
||||
undated = set(whole.unique_id[whole["birth_date"].isna()]) if "birth_date" in fields else set()
|
||||
# Answers are kept by record; a person is known by any of hers, whatever joined since.
|
||||
whose = persons.set_index("unique_id")["cluster_id"].to_dict()
|
||||
answered = {frozenset(whose.get(r, r) for r in e) for e in decided}
|
||||
lone = set() # persons whose identifier is carried by one record only
|
||||
for f in ids:
|
||||
carried = persons.dropna(subset=[f]).groupby(["cluster_id", f]).size()
|
||||
@@ -439,7 +442,7 @@ def run_link(p: str, node: Link):
|
||||
very same identifier on a record that says nothing else (a scan read only in part)."""
|
||||
a, b = r.unique_id_l, r.unique_id_r
|
||||
sides = [(getattr(r, f"{f}_l"), getattr(r, f"{f}_r")) for f in known]
|
||||
if frozenset((a, b)) in decided or any(
|
||||
if frozenset((a, b)) in answered or any(
|
||||
pd.notna(x) and pd.notna(y) and x != y for x, y in sides
|
||||
):
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""A reviewer's "they are different people" is about the persons: it holds when more records
|
||||
join one of them, whichever record the person is known by afterwards."""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
PEOPLE = [("1001", "ANA LOPEZ RUIZ", "1980-01-01"), ("2002", "BEATRIZ MORA DIAZ", "1980-01-01")]
|
||||
PEOPLE += [(f"9{k:03d}", f"PERSONA {k} DE RELLENO", f"19{50 + k}-0{1 + k % 9}-11")
|
||||
for k in range(30)] # fmt: skip
|
||||
|
||||
|
||||
def graph(db) -> dict:
|
||||
fields = {"record_number": "num", "full_name": "nombre", "birth_date": "nac", "nss": "nss"}
|
||||
return {"nodes": [
|
||||
{"id": "people", "kind": "source", "source": "dlt.sources.sql_database:sql_table",
|
||||
"args": {"credentials": f"sqlite:///{db}", "table": "people"}},
|
||||
{"id": "identity", "kind": "map", "inputs": ["people"], "fields": fields},
|
||||
{"id": "persons", "kind": "link", "inputs": ["identity"], "fields": list(fields)},
|
||||
]} # fmt: skip
|
||||
|
||||
|
||||
def insert(db, rows) -> None:
|
||||
with sqlite3.connect(db) as con:
|
||||
con.execute(
|
||||
"create table if not exists people "
|
||||
"(id integer primary key, num text, nombre text, nac text, nss text)"
|
||||
)
|
||||
con.executemany("insert into people (num, nombre, nac, nss) values (?, ?, ?, ?)", rows)
|
||||
|
||||
|
||||
def test_an_answer_outlives_the_record_a_person_was_known_by(platform, tmp_path):
|
||||
db, drawn = tmp_path / "people.db", tmp_path / "pipeline.json"
|
||||
insert(db, [(*p, None) for p in PEOPLE])
|
||||
drawn.write_text(json.dumps(graph(db)))
|
||||
platform.save("pipelines", "site", drawn)
|
||||
platform.ingest()
|
||||
queue = "select person, candidate from bronze.n__site__persons__review"
|
||||
((a, b),) = platform.query(queue)
|
||||
platform.run("python", "-c", "from persistance import nodes; "
|
||||
f"nodes.decide_persons({a!r}, {b!r}, False, 'reviewer')") # fmt: skip
|
||||
platform.ingest()
|
||||
assert platform.query(queue) == []
|
||||
|
||||
# Forty more documents of each woman: whichever of her records her person was known by,
|
||||
# one of these is (almost surely) it now.
|
||||
insert(db, [(num, None, None, f"{num}{k:07d}") for num in ("1001", "2002") for k in range(40)])
|
||||
platform.ingest()
|
||||
lowest = "select min(_record) from bronze.n__site__persons where record_number = '{}'"
|
||||
known = {platform.query(lowest.format(n))[0][0] for n in ("1001", "2002")}
|
||||
assert known != {a, b}
|
||||
assert platform.query(queue) == []
|
||||
Reference in New Issue
Block a user