fix(graph): keep distinct entities that share a substring prefix (#5630)

This commit is contained in:
Yash Singh
2026-06-19 12:23:15 +05:30
committed by GitHub
parent ffa334537a
commit ff53fd60b7
2 changed files with 18 additions and 2 deletions
+8 -2
View File
@@ -352,6 +352,12 @@ def _extract_entities_from_doc(doc) -> List[Tuple[str, str]]:
best[k] = (t, e)
deduped = list(best.values())
# Remove entities that are substrings of longer entities
# Remove entities that are whole-word substrings of longer entities.
# Word-boundary anchoring avoids dropping distinct entities that only share a
# leading substring (e.g. "Sam" must survive alongside "Samsung").
all_lower = [e[1].lower() for e in deduped]
return [(t, e) for t, e in deduped if not any(e.lower() != o and e.lower() in o for o in all_lower)]
return [
(t, e)
for t, e in deduped
if not any(e.lower() != o and re.search(rf"\b{re.escape(e.lower())}\b", o) for o in all_lower)
]