feat(normalizer): add SPOUSE_OF resolution to persons_tree
This commit is contained in:
@@ -207,3 +207,38 @@ def _deduplicate(persons: list[dict]) -> tuple[list[dict], list[str]]:
|
||||
result.append(p)
|
||||
|
||||
return result, skipped
|
||||
|
||||
|
||||
def _resolve_spouses(
|
||||
persons: list[dict], index: dict[str, list[str]]
|
||||
) -> tuple[list[dict], list[dict]]:
|
||||
"""Emit SPOUSE_OF edges from each person's _spouse_raw field."""
|
||||
relationships: list[dict] = []
|
||||
unresolved: list[dict] = []
|
||||
emitted: set[frozenset] = set()
|
||||
|
||||
for p in persons:
|
||||
raw = (p.get("_spouse_raw") or "").strip()
|
||||
if not raw:
|
||||
continue
|
||||
row_id = p["rowId"]
|
||||
matched_id, reason = _resolve_one(raw, index)
|
||||
if matched_id:
|
||||
edge = frozenset([row_id, matched_id])
|
||||
if edge not in emitted:
|
||||
emitted.add(edge)
|
||||
relationships.append({
|
||||
"personId": row_id,
|
||||
"relatedPersonId": matched_id,
|
||||
"type": "SPOUSE_OF",
|
||||
"source": "verheiratet_mit",
|
||||
})
|
||||
else:
|
||||
unresolved.append({
|
||||
"rowId": row_id,
|
||||
"field": "verheiratet_mit",
|
||||
"raw": raw,
|
||||
"reason": reason,
|
||||
})
|
||||
|
||||
return relationships, unresolved
|
||||
|
||||
Reference in New Issue
Block a user