Skip to content

Feature request: Moroccan recognizers (MA_RIB, MA_CIN, MA_CNSS) #2474

Open

Description

@ennachite

Is your feature request related to a problem? Please describe.
Presidio has no recognizer for Morocco, and no predefined recognizer that declares Arabic (ar). Moroccan text, in Arabic or French, carries identifiers that nothing detects today: the bank account identifier (RIB), the national identity card number (CIN) and the social security number (CNSS).

Describe the solution you'd like
Three country-specific recognizers under predefined_recognizers/country_specific/morocco/, shipped disabled, for languages ar and fr. I have them written and tested, and I would send them as three small PRs, one recognizer each.

Entity Shape Scoring
MA_RIB 24 digits: bank (3), locality (3), account (16), key (2) 0.3 in one run, 0.2 in groups. A number that fails the key is dropped.
MA_CIN one or two letters + 5 or 6 digits 0.2 / 0.1, and 0.05 for the form with a space
MA_CNSS 9 digits, first digit 1 0.05

Sources:

  • RIB structure: U.S. Social Security Administration, POMS GN 02402.297.
    The key makes the 24 digits divisible by 97. No official text states thisrule; it holds for the RIB that Bank Al-Maghrib published for the special fund no. 126, and for three other published RIBs from three other banks. Because about 1 random number in 97 also passes, the key only removes candidates and never raises the score.
  • CIN: law no. 04-20 (name of the number), the World Bank ID4D country diagnostic for Morocco (two letters + six digits + two check digits), and the NARSA road-offences portal, which accepts one or two letters followed by one to six digits.
  • CNSS: the same World Bank report (nine digits, leading 1, two control digits).

Each recognizer comes with a configuration-path test through RecognizerRegistryProvider, exact score assertions, lookalike negatives, and context tests in ar and fr.

Two things I would like your view on before I open the PRs:

  1. These would be the first ar entries, so ar joins the known languages asserted in test_recognizer_registry.py. Is that welcome?
  2. No Arabic or French model is installed in CI. For context tests I use a small test helper that tokenizes with spaCy's rule-based tokenizers (spacy.blank). Is that acceptable in the test suite?

Describe alternatives you've considered

  • Promoting a RIB to 1.0 when the key passes, as IbanRecognizer does. I chose not to: a bare 24-digit number has no country prefix, so a filterable score seemed safer.
  • Using the labels "RIB", "CIN" as default context words. I left them out: context matching is by substring, and they sit inside common French words ("tribunal", "cinq", "médecin").
  • One PR with all three. I prefer three, so each can be reviewed on its own evidence.

Additional context
I also looked at the Moroccan passport, the company identifier (ICE) and the driving licence. I am leaving them out for now because I could not find a source strong enough for the format or the check rule.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions