Inconsistent detection of PII written with non-ASCII digits (Arabic-Indic, Persian, ...), first step toward Arabic support
Is your feature request related to a problem? Please describe.
Presidio has no Arabic support yet (no language config, context words or Arabic-region recognizers), and a first measurement shows a concrete gap that affects every language using non-ASCII digits: PII written with Arabic-Indic (٠١٢٣٤٥٦٧٨٩), Persian (۰۱۲…) or other Unicode decimal digits is detected inconsistently, and most sensitive identifiers are missed entirely.
I took every string literal containing digits from the analyzer's own recognizer tests (1,839 strings), kept those each PatternRecognizer detects in ASCII form, swapped the ASCII digits for Arabic-Indic digits, and re-ran the same recognizer (90 recognizers, main at 4f0e236):
| Outcome with Arabic-Indic digits | Recognizers (examples) |
|---|---|
| never detected (0%) | CreditCardRecognizer 0/18, IbanRecognizer 0/157, UsSsnRecognizer 0/76, UsPassportRecognizer 0/100, InAadhaarRecognizer 0/22, KrRrnRecognizer 0/18, ... (44 recognizers) |
| partially detected | DateRecognizer 4/36, IpRecognizer 3/84, FiPersonalIdentityCodeRecognizer 19/28, ... |
| always detected (100%) | PhUmidRecognizer 61/61, SePersonnummerRecognizer 35/35, ItPassportRecognizer 17/17, ... |
| raises | SgUenRecognizer (ValueError, also reported in #2356) |
The split follows implementation details: patterns using \d match any Unicode digit while [0-9] patterns do not, and some checksum code handles non-ASCII digits while some does not. So a credit card number written ٤٠١٢٨٨٨٨٨٨٨٨١٨٨١ passes through unredacted, while other identifiers in the same text are caught.
Describe the solution you'd like
Translate every Unicode decimal digit (unicodedata category Nd) to its ASCII digit before pattern matching and validation in PatternRecognizer. Each digit is one code point mapped to one code point, so result spans are unchanged and no offset mapping is needed. IbanRecognizer has its own matching loop and needs the same line.
I have this working on a branch (19 lines plus a test):
- the audit above goes to 100% detection parity for all 90 recognizers, and the
SgUenRecognizercrash disappears; - the full analyzer test suite gives the same results before and after (3,344 passed; the remaining failures are optional dependencies missing in my environment and occur on
maintoo); - cost: the translation table (670 digits) is built once at import in about 0.05 s; translating a 4,650-character note takes about 3 µs.
This changes detection results for existing users (more detections on text with non-ASCII digits), so I'd like your view before opening the PR: should it be the default, or opt-in (e.g. a PatternRecognizer flag)?
Planned follow-ups for Arabic (each its own issue/PR, after this one):
- Arabic context words and clitics: Arabic attaches prefixes to words (و, ف, ب, ك, ل, ال), so
والرقمdoes not match the context wordرقم; the same family of problem as Korean in #2216 / #2341. I'd measure context hit rates on Arabic text first. - Recognizers for national identifiers of Arabic-speaking countries (e.g. UAE Emirates ID, Saudi national ID), each with its checksum verified against an official specification before submission.
- A documented Arabic NER configuration through the transformers NLP engine.
I prepared this with AI assistance and reviewed it; I speak Arabic and work on clinical NLP.