feat(analyzer): add Danish CPR number recognizer#2196
Open
WMOlsen wants to merge 1 commit into
Open
Conversation
Add DkCprRecognizer for the 10-digit Danish personnummer (DK_CPR_NUMBER), disabled by default and tagged country_code: dk. Validation derives the full four-digit birth year from the official CPR century table so leap days are handled correctly, and applies the modulus-11 checksum as confirmation only: a passing checksum promotes the match, a failing one leaves the pattern score untouched. CPR-kontoret discontinued the mandatory modulus-11 control in 2007, so numbers issued since then are not guaranteed to satisfy it, and a hard checksum gate would drop valid numbers.
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 a Danish CPR number (
DK_CPR_NUMBER) predefined recognizer topresidio-analyzer. Disabled by default indefault_recognizers.yaml, taggedcountry_code: dk.DK_CPR_NUMBER(DkCprRecognizer): the 10-digit Danish personnummer, formatDDMMYY-SSSS(hyphenated) orDDMMYYSSSS(contiguous).290204= 29 Feb 1904 is accepted,290203= 29 Feb 1903 is rejected).4 3 2 7 6 5 4 3 2 1) is applied as confirmation only: a passing checksum promotes the match to full confidence, but a failing checksum never rejects the candidate. CPR-kontoret discontinued the mandatory modulus-11 control in 2007 because several birth dates had exhausted their supply of control-digit-valid sequence numbers, so numbers issued since then are not guaranteed to satisfy it. A hard checksum gate would silently drop valid personal data, which is the failure mode a PII detector must avoid.\b-anchored patterns (hyphenated0.5, contiguous0.3); no boundary-less fallback, to avoid matching inside longer numeric strings.CHANGELOG.md,docs/supported_entities.md,default_recognizers.yaml, andpredefined_recognizers/__init__.py.tests/test_dk_cpr_recognizer.py; all cases pass locally.ruff checkandruff format --checkpass on the changed files.Known limitations: the contiguous 10-digit form can collide with other 10-digit numeric identifiers; this is mitigated by date validation, context words, and the lower
0.3pattern score. Healthcare replacement numbers (erstatningsnumre, day + 60) are intentionally not matched, as they are a regional-system convention rather than CPR-register numbers. Space-separated forms (DDMMYY SSSS) are not matched.Issue reference
N/A
Checklist