Coverage for presidio_analyzer / predefined_recognizers / country_specific / singapore / sg_fin_recognizer.py: 100%
9 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
1from typing import List, Optional
3from presidio_analyzer import Pattern, PatternRecognizer
5# Weak pattern: all FIN number start with "S", "T", "F", "G" or "M"
6# and ends with a character, e.g., S2740116C
7# Ref: https://en.wikipedia.org/wiki/National_Registration_Identity_Card
10class SgFinRecognizer(PatternRecognizer):
11 """
12 Recognize SG FIN/NRIC number using regex.
14 :param patterns: List of patterns to be used by this recognizer
15 :param context: List of context words to increase confidence in detection
16 :param supported_language: Language this recognizer supports
17 :param supported_entity: The entity this recognizer can detect
18 """
20 PATTERNS = [
21 Pattern("Nric (weak)", r"(?i)(\b[A-Z][0-9]{7}[A-Z]\b)", 0.3),
22 Pattern("Nric (medium)", r"(?i)(\b[STFGM][0-9]{7}[A-Z]\b)", 0.5),
23 ]
25 CONTEXT = ["fin", "fin#", "nric", "nric#"]
27 def __init__(
28 self,
29 patterns: Optional[List[Pattern]] = None,
30 context: Optional[List[str]] = None,
31 supported_language: str = "en",
32 supported_entity: str = "SG_NRIC_FIN",
33 name: Optional[str] = None,
34 ):
35 patterns = patterns if patterns else self.PATTERNS
36 context = context if context else self.CONTEXT
37 super().__init__(
38 supported_entity=supported_entity,
39 patterns=patterns,
40 context=context,
41 supported_language=supported_language,
42 name=name,
43 )