Repository navigation
feat(analyzer): add Malaysian SSM business registration number recognizer - #2553
Open
aimanmalib wants to merge 2 commits into
Open
aimanmalib wants to merge 2 commits into
aimanmalib wants to merge 2 commits into
Conversation
…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
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
MySsmRecognizerfor Malaysian business and company registration numbers issued by SSM (Companies Commission ofMalaysia). This is the separate MY_SSM PR I mentioned in #2478 (#2478 (comment)).
MY_SSM,COUNTRY_CODE = "my", directorycountry_specific/malaysia/, shippedenabled: false, languageen.YYYYTTNNNNNN: registration year, entity type01-06, six-digit serial. Thereis no check digit, so the recognizer uses
invalidate_resultrather thanvalidate_result: it drops numbers whose year isbefore 1900 or after the current year, whose entity type is not
01-06, or whose LLP type (04-06) has a year before2012, 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.
Example Sdn Bhd (123456-X). The letter is not documented, so this form is not validated and scores 0.1. A bracketed code onits 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-xdoes not match, and a test pins it).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 outreg,co,no,rocandrob, since in the default substring mode they matchregion,cost,phone,processandproblem.ssmstill matches insideassessment; I kept it because it is the most common label for these numbers, and a test pinsthat behaviour.
__init__.pyfiles,default_recognizers.yamlanddocs/supported_entities.md; Malaysia added to thecountry 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
YYYYreads as a birth year and month there. I counted it exactly over every 8-digit prefix (both sets of checks only look atthe 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
201103258714can come back as both entities, andcontext 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 atwo-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 under0.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):form;
bracketed codes without context;
RecognizerRegistryProvider, run inAnalyzerEnginewithspaCy, 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 therecognizer from
__all__or the YAML each makes tests fail. The full analyzer suite passes (3833 passed, 0 failed, with allextras, against 3734 passed on
main), and changed-line coverage measured withdiff-coveris 100%.ruff checkandruff format --checkpass 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
RecognizerRegistryProvider