Skip to content

feat(analyzer): Add CaBnRecognizer for Canadian Business Numbers (CA_BN) - #2207

Open
Joey239716 wants to merge 5 commits into
data-privacy-stack:mainfrom
Joey239716:feat/ca-bn-recognizer
Open

feat(analyzer): Add CaBnRecognizer for Canadian Business Numbers (CA_BN)#2207
Joey239716 wants to merge 5 commits into
data-privacy-stack:mainfrom
Joey239716:feat/ca-bn-recognizer

Conversation

@Joey239716

Copy link
Copy Markdown

Change Description

Adds CaBnRecognizer for the Canadian Business Number (entity type CA_BN), a 9-digit business identifier issued by the Canada Revenue Agency.

  • Detects the bare 9-digit form (weak pattern, 0.05, relies on context words) and the 15-character program account form such as 123456782 RT 0001 (medium pattern, 0.5), covering the common CRA program identifiers RT, RP, RC, RM, RR, RZ
  • Validates every match with the Luhn checksum over the 9-digit base via invalidate_result (same scheme as CA_SIN), plus an all-same-digit guard since 000000000 passes Luhn
  • Bilingual English/French context words (business number / numéro d'entreprise, CRA / ARC, GST / TPS, etc.)
  • Registered in default_recognizers.yaml with enabled: false and en/fr support, following the CA_SIN and CA_POSTAL_CODE (feat: Add CaPostalCodeRecognizer for Canadian postal codes (CA_POSTAL… #2204) precedents
  • Parametrized unit tests covering valid weak/medium forms, bilingual context, checksum failures, all-same-digit inputs, unknown program identifiers, and wrong lengths
  • Documentation added to docs/supported_entities.md

Issue reference

Fixes #2206

Checklist

  • I have reviewed the contribution guidelines
  • I agree to follow this project's Code of Conduct
  • I confirm that I have the right to submit this contribution and that it does not knowingly contain proprietary or confidential code.
  • My code includes unit tests
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates / additions if required

Adds CaBnRecognizer detecting the 9-digit CRA Business Number and its
15-character program account form (e.g. 123456782 RT 0001), validated
with the Luhn checksum. Registered disabled by default with en/fr
support, following the CA_SIN and CA_POSTAL_CODE precedents.
@Joey239716 Joey239716 changed the title feat: Add CaBnRecognizer for Canadian Business Numbers (CA_BN) feat(analyzer): Add CaBnRecognizer for Canadian Business Numbers (CA_BN) Jul 31, 2026
Replace \b word boundaries with lookaround anchors so 9-digit runs
joined to larger tokens by '.', '/' or '-' (serial numbers, decimals)
are not matched, with regression tests for those cases. Update the
CRA reference link and document the SIN ambiguity in the docstring.
@Joey239716

Copy link
Copy Markdown
Author

Hi @SharonHart, gentle nudge on this PR when you get a chance, Thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add Canadian Business Number recognizer (CA_BN)

1 participant