from __future__ import annotations import re from src.domain import EntityType, Method, Workflow from src.schemas import Span EMAIL_RE = re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b") PHONE_RE = re.compile(r"(? Span: return Span( start=start, end=end, entity_type=entity_type, surface=text[start:end], confidence=0.4, method=Method.BASELINE.value, rule_id=rule_id, workflow=Workflow.DETECTED, reason="Regex-only baseline without checksum or digit fold", ) def analyze_regex_only(text: str) -> list[Span]: """Naive recognizer: ASCII regex, no Persian digits, no checksum, no hard-negative filter.""" found: list[Span] = [] for match in EMAIL_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.EMAIL, "base.email")) for match in PHONE_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.PHONE, "base.phone")) for match in TEN_DIGIT_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.IR_NATIONAL_ID, "base.ten_digit")) for match in SIXTEEN_DIGIT_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.CREDIT_CARD, "base.sixteen_digit")) for match in IBAN_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.IBAN, "base.iban")) for match in EMPLOYEE_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.EMPLOYEE_ID, "base.employee")) for match in HONORIFIC_RE.finditer(text): found.append(_span(text, match.start(), match.end(), EntityType.PERSON, "base.honorific")) return found