feat(nlp-service): wire NLP_FUZZY_THRESHOLD env var with 0-100 validation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,9 +13,10 @@ from person_matcher import PersonMatcher
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
# ── Module-level PersonMatcher (set at startup) ───────────────────────────────
|
||||
# ── Module-level PersonMatcher and fuzzy threshold (set at startup) ──────────
|
||||
|
||||
_matcher: PersonMatcher | None = None
|
||||
_fuzzy_threshold: int = 80
|
||||
|
||||
|
||||
def set_person_matcher(m: PersonMatcher) -> None:
|
||||
@@ -27,6 +28,11 @@ def get_person_matcher() -> PersonMatcher | None:
|
||||
return _matcher
|
||||
|
||||
|
||||
def set_fuzzy_threshold(threshold: int) -> None:
|
||||
global _fuzzy_threshold
|
||||
_fuzzy_threshold = threshold
|
||||
|
||||
|
||||
# ── Preposition sets ──────────────────────────────────────────────────────────
|
||||
|
||||
_SENDER_PREPS: dict[str, frozenset[str]] = {
|
||||
@@ -155,7 +161,7 @@ def _extract_persons_and_role(
|
||||
|
||||
preps = _ALL_PERSON_PREPS[lang]
|
||||
stops = preps | _DATE_BEFORE[lang] | _DATE_AFTER[lang] | _DATE_BETWEEN[lang] | _EXTRA_SPAN_STOPS[lang]
|
||||
matches = m.find_in_query(query, preps, stop_tokens=stops)
|
||||
matches = m.find_in_query(query, preps, stop_tokens=stops, threshold=_fuzzy_threshold)
|
||||
|
||||
person_names = [text for text, _ in matches]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user