File size: 2,531 Bytes
34445b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import re


_ScamSignal = re.IGNORECASE

_SCAM_KEYWORDS_RE = re.compile(
    r"(?:bisp|ehsaas|ehsan|ایڈی|eidi|identifi|شناخت|پہچان|"
    r"کا?رڈ|card|gover|حکومت|سرکار|وزیر|sarkar|"
    r"8171|786|پنج\s*هزار|5000|ایک\s*سو\s*ایک|"
    r"پکی\s*خبر|verified|پکی|سچی|سمجھو|سمجھ|"
    r"فون|phone|moj| mobil|رقم|amount|rb?sid|رسید)",
    re.IGNORECASE,
)


def has_scam_signals(text: str) -> bool:
    """Return True if *text* contains known scam-related keywords or numbers."""
    if not text:
        return False
    return bool(_SCAM_KEYWORDS_RE.search(text))

_PHONETIC_DIGITS_URDU = {
    "ایک": "1", "اک": "1",
    "دو": "2",
    "تین": "3", "tin": "3",
    "چار": "4", "char": "4",
    "پانچ": "5",
    "چھ": "6", "che": "6",
    "سات": "7", "sat": "7",
    "آٹھ": "8", "ath": "8",
    "نو": "9", "nau": "9",
    "دس": "10", "das": "10",
}

_PHONETIC_RE = re.compile(
    r"(?:ایک|اک|دو|تین|tin|چار|char|پانچ|چھ|che|سات|sat|آٹھ|ath|نو|nau|دس|das)"
    r"(?:\s+(?:و|aur)\s+(?:ایک|اک|دو|تین|tin|چار|char|پانچ|چھ|che|سات|sat|آٹھ|ath|نو|nau|دس|das))+",
    re.IGNORECASE,
)


def extract_numbers(text: str) -> list[str]:
    """Extract numeric tokens from *text*.

    Finds bare digits (e.g. "8171", "786") and also converts phonetic Urdu
    numbers written in script (e.g. "ایٹ ون سیون ون") into digit strings
    when possible.  Returns a list of digit strings.
    """
    if not text:
        return []

    digits: list[str] = re.findall(r"\b\d{4,5}\b", text)

    for m in _PHONETIC_RE.finditer(text):
        raw = m.group(0)
        built = ""
        for token in raw.split():
            if token in ("و", "aur"):
                continue
            built += _PHONETIC_DIGITS_URDU.get(token, "")
        if built and built not in digits:
            digits.append(built)

    return digits


def number_note_for_claim(numbers: list[str]) -> str | None:
    """Return a SearchableClaim note if *numbers* contains 4- or 5-digit
    values that may be tied to known scams or government programs."""
    if not numbers:
        return None
    notable = [n for n in numbers if len(n) in (4, 5)]
    if not notable:
        return None
    joined = ", ".join(notable)
    return (
        f"Numbers found in transcript: {joined}. "
        "Check if any of these numbers are associated with a known scam "
        "or government program."
    )