Coverage for presidio_analyzer / predefined_recognizers / country_specific / india / in_passport_recognizer.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from typing import List, Optional 

2 

3from presidio_analyzer import Pattern, PatternRecognizer 

4 

5 

6class InPassportRecognizer(PatternRecognizer): 

7 """ 

8 Recognizes Indian Passport Number. 

9 

10 Indian Passport Number is a eight digit alphanumeric number. 

11 

12 Reference: 

13 https://www.bajajallianz.com/blog/travel-insurance-articles/where-is-passport-number-in-indian-passport.html 

14 

15 :param patterns: List of patterns to be used by this recognizer 

16 :param context: List of context words to increase confidence in detection 

17 :param supported_language: Language this recognizer supports 

18 :param supported_entity: The entity this recognizer can detect 

19 """ 

20 

21 PATTERNS = [ 

22 Pattern( 

23 "PASSPORT", 

24 r"\b[A-Z][1-9]\d\s?\d{4}[1-9]\b", 

25 0.1, 

26 ), 

27 ] 

28 

29 CONTEXT = ["passport", "indian passport", "passport number"] 

30 

31 def __init__( 

32 self, 

33 patterns: Optional[List[Pattern]] = None, 

34 context: Optional[List[str]] = None, 

35 supported_language: str = "en", 

36 supported_entity: str = "IN_PASSPORT", 

37 name: Optional[str] = None, 

38 ): 

39 patterns = patterns if patterns else self.PATTERNS 

40 context = context if context else self.CONTEXT 

41 super().__init__( 

42 supported_entity=supported_entity, 

43 patterns=patterns, 

44 context=context, 

45 supported_language=supported_language, 

46 name=name, 

47 )