Skip to content

feat(analyzer): add Malaysian SSM business registration number recognizer - #2553

Open
aimanmalib wants to merge 2 commits into
data-privacy-stack:mainfrom
aimanmalib:feat/my-ssm-recognizer
Open

aimanmalib wants to merge 2 commits into
data-privacy-stack:mainfrom
aimanmalib:feat/my-ssm-recognizer

Conversation

@aimanmalib

Copy link
Copy Markdown

Change Description

Adds MySsmRecognizer for Malaysian business and company registration numbers issued by SSM (Companies Commission of
Malaysia). This is the separate MY_SSM PR I mentioned in #2478 (#2478 (comment)).

  • Entity MY_SSM, COUNTRY_CODE = "my", directory country_specific/malaysia/, shipped enabled: false, language en.
  • 12-digit format used since 11 October 2019, YYYYTTNNNNNN: registration year, entity type 01-06, six-digit serial. There
    is no check digit, so the recognizer uses invalidate_result rather than validate_result: it drops numbers whose year is
    before 1900 or after the current year, whose entity type is not 01-06, or whose LLP type (04-06) has a year before
    2012, when the Limited Liability Partnerships Act 2012 (Act 743) came into force. A valid number keeps its pattern score of
    0.4 instead of jumping to 1.0.
  • Older company number, still printed after many company names: up to seven digits, a dash and one capital letter, for example
    Example Sdn Bhd (123456-X). The letter is not documented, so this form is not validated and scores 0.1. A bracketed code on
    its own is just as often a product or model code, so it only becomes useful with context. The letter stays upper case even
    though patterns match case-insensitively by default (123456-x does not match, and a test pins it).
  • Context words are single words only: ssm, registration, pendaftaran, company, syarikat, sdn, bhd, berhad,
    enterprise, plt. With the default enhancer, prefix context raises 0.4 to 0.75 and 0.1 to 0.45. I left out reg, co,
    no, roc and rob, since in the default substring mode they match region, cost, phone, process and problem.
    ssm still matches inside assessment; I kept it because it is the most common label for these numbers, and a test pins
    that behaviour.
  • Registered in both __init__.py files, default_recognizers.yaml and docs/supported_entities.md; Malaysia added to the
    country list in docs/analyzer/filtering_by_country.md.

No existing recognizer, default or shared code changes; the only behaviour change is a new recognizer, disabled by default.

Overlap with #2478 (MY_NRIC), which is still open: some valid SSM numbers also pass the MyKad checks in that branch, because
YYYY reads as a birth year and month there. I counted it exactly over every 8-digit prefix (both sets of checks only look at
the first 8 digits): 15.14% of valid SSM numbers also pass the MY_NRIC checks, which is 0.21% of valid MyKad numbers. It only
happens for registration years 1901-1912 and 2001-2012. From 2013 on, the "month" would be 13 or more, so no number in that
range is read as both. If both recognizers are enabled, a number such as 201103258714 can come back as both entities, and
context words decide which scores higher. This PR does not change MY_NRIC.

Both PRs add country_specific/malaysia/__init__.py. This PR does not depend on #2478: whichever is merged second needs a
two-line merge in that file (the import and __all__), and I'm happy to rebase.

Regex backtracking: both patterns are anchored with lookarounds and have no nested quantifiers. Adversarial inputs of 100,000
to 110,000 characters (repeated digits, 1- repeated, brackets followed by digits, repeated years ending in -X) run in under
0.02 s each, and a test fails if any takes 0.5 s.

Tests (tests/test_my_ssm_recognizer.py, 96 tests, all values synthetic):

  • exact spans and scores for both forms, each entity type code, the current year, two numbers in one text, and the bracketed old
    form;
  • invalid years, unknown entity types, LLP types before 2012, numbers embedded in longer numbers or tokens, wrong separator or letter, and
    bracketed codes without context;
  • the configuration path: the shipped YAML entry enabled through RecognizerRegistryProvider, run in AnalyzerEngine with
    spaCy, asserting scores with and without context, including the left-out words above and a context word after the number;
  • supported_countries: ["my"] keeps this recognizer and drops a Singapore one.

I checked that the tests catch broken logic: removing the entity type check, the LLP check or the year check, loosening any of
the three pattern boundaries, letting the old-form letter be lower case, changing the YAML country_code, or dropping the
recognizer from __all__ or the YAML each makes tests fail. The full analyzer suite passes (3833 passed, 0 failed, with all
extras, against 3734 passed on main), and changed-line coverage measured with diff-cover is 100%. ruff check and
ruff format --check pass with the pinned ruff 0.9.2.

This is a standalone port of the pattern and validation part of MyPII (https://github.com/sasateguh/mypii, MIT). MyPII's OCR
normalisation, line-break handling, negative context words and context classifier are not included. I wrote this with help
from Claude Code and reviewed every line.

Issue reference

Part of #2458

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
  • My PR description states any change to existing behavior and any possible impact on detection accuracy or security
  • If I added or changed a recognizer, it has a test that enables it in a YAML configuration and loads it through RecognizerRegistryProvider

…izer

Adds MySsmRecognizer (MY_SSM, country code "my", disabled by default in
default_recognizers.yaml). The 12-digit SSM number issued since October
2019 is YYYY (registration year) + TT (entity type 01-06) + a 6-digit
serial. With no check digit, invalidate_result rejects years outside
1900..current year, unknown entity types and LLP types (04-06) before
2012 (Act 743); a valid match keeps its pattern score of 0.4. The older
company form (123456-X), alone or in brackets after the company name,
scores 0.1 and relies on context words.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant