Coverage for presidio_analyzer / predefined_recognizers / country_specific / us / us_itin_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
6class UsItinRecognizer(PatternRecognizer):
7 """
8 Recognizes US ITIN (Individual Taxpayer Identification Number) using regex.
10 :param patterns: List of patterns to be used by this recognizer
11 :param context: List of context words to increase confidence in detection
12 :param supported_language: Language this recognizer supports
13 :param supported_entity: The entity this recognizer can detect
14 """
16 PATTERNS = [
17 Pattern(
18 "Itin (very weak)",
19 r"\b9\d{2}[- ](5\d|6[0-5]|7\d|8[0-8]|9([0-2]|[4-9]))\d{4}\b|\b9\d{2}(5\d|6[0-5]|7\d|8[0-8]|9([0-2]|[4-9]))[- ]\d{4}\b", # noqa: E501
20 0.05,
21 ),
22 Pattern(
23 "Itin (weak)",
24 r"\b9\d{2}(5\d|6[0-5]|7\d|8[0-8]|9([0-2]|[4-9]))\d{4}\b",
25 0.3,
26 ),
27 Pattern(
28 "Itin (medium)",
29 r"\b9\d{2}[- ](5\d|6[0-5]|7\d|8[0-8]|9([0-2]|[4-9]))[- ]\d{4}\b",
30 0.5,
31 ),
32 ]
34 CONTEXT = ["individual", "taxpayer", "itin", "tax", "payer", "taxid", "tin"]
36 def __init__(
37 self,
38 patterns: Optional[List[Pattern]] = None,
39 context: Optional[List[str]] = None,
40 supported_language: str = "en",
41 supported_entity: str = "US_ITIN",
42 name: Optional[str] = None,
43 ):
44 patterns = patterns if patterns else self.PATTERNS
45 context = context if context else self.CONTEXT
46 super().__init__(
47 supported_entity=supported_entity,
48 patterns=patterns,
49 context=context,
50 supported_language=supported_language,
51 name=name,
52 )