Repository navigation
Conversation
Pattern-based recognizer for RAMQ (NAM) numbers: 4 letters followed by 8 digits, with optional space or dash separators. No check digit is published, so none is checked and no score is promoted to 1.0. Two mutually exclusive patterns rank a match by its embedded birth date: strong (0.65) when the month is 01-12 or 51-62 and the day is 01-31, medium (0.5) otherwise. The date never drops a match. Disabled by default; registered in the YAML, the exports and the supported entities docs, with a configuration-path test.
Author
|
Closing this in favour of canpii (https://github.com/ArthurJZL/canpii), which already provides a RAMQ recognizer with the official sources, to avoid two overlapping efforts. Thanks to @ArthurJZL for the sources and the review offer. Discussion continues on #2482. |
Collaborator
|
@mdeloupy how about adding canpii to the community list in Presidio? This would help users find the Canadian recognizers and models more easily. |
5 of 8 tasks
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
Adds
CaRamqRecognizer, a pattern-based recognizer for Quebec health insurance numbers (RAMQ, also called "NAM"), entityCA_RAMQ.ABCD 1234 5678,ABCD-12-34-56-78,ABCD12345678). Matching is case-insensitive, like the other Canadian recognizers.CA RAMQ (strong), 0.65: the embedded birth date is plausible (month01-12for men or51-62for women, day01-31).CA RAMQ (medium), 0.5: any other 4 letters + 8 digits.validate_resultand no match is promoted to 1.0.ramq,assurance maladie,health insurance,carte soleil,health card,medicare card. Barenamandcardare left out on purpose: substring matching makes them fire on "dynamic", "naming" and similar words.enandfr. Country-specific, soCOUNTRY_CODE = "ca"andenabled: falseby default.__init__.pyexports,conf/default_recognizers.yaml, anddocs/supported_entities.md.Existing behavior: no change. The PR adds new files and additive lines only (exports, a YAML entry that ships disabled, a docs row). No existing recognizer's patterns, scores or context are touched.
Impact on detection accuracy: none for existing users, because the recognizer is disabled by default. When enabled, it has an expected false-positive surface: with no check digit, any token shaped like 4 letters + 8 digits matches (for example an order reference such as
ABCD12345678scores 0.5, or 0.65 if its digits happen to look like a date). Context words raise real matches, and a score threshold filters the rest. The format (surname letters, birth year, month with 50 added for women, day, two administrative digits) comes from secondary sources : https://tools.tnaado.ca/canadian/ramq-number-validator/Impact on security: no PII is logged. The patterns use bounded quantifiers only, and I timed them on 10k-24k character adversarial inputs (long runs of letters, digits, and repeated
ABCD 85): at most about 4 ms, so no catastrophic backtracking.How it was tested: unit tests with synthetic values only (no real RAMQ numbers), and no evaluation on a dataset.
Issue reference
Fixes #2482
Tests
presidio-analyzer/tests/test_ca_ramq_recognizer.py, 61 tests, 100% coverage of the new module:RecognizerRegistryProviderfromdefault_recognizers.yamlinenandfr(thefrcase sets the top-levelsupported_languages), and from a temporary YAML withenabled: true, asserting detectionChecklist
RecognizerRegistryProvider