Coverage for presidio_analyzer / predefined_recognizers / country_specific / germany / de_passport_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 DePassportRecognizer(PatternRecognizer):
7 """
8 Recognizes German passport numbers (Reisepassnummern) using regex.
10 German passports are issued by the Bundesdruckerei on behalf of the
11 Bundesrepublik Deutschland. The document number consists of 9 alphanumeric
12 characters and appears on the data page and in the Machine Readable Zone (MRZ).
14 Legal basis: Passgesetz (PassG) § 4, Passverordnung (PassV).
15 Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
17 Format:
18 - 9 alphanumeric characters (uppercase letters from the limited set
19 C, F, G, H, J, K, L, M, N, P, R, T, V, W, X, Y, Z and digits 0–9)
20 - First character: typically a letter from the series identifier
21 - Followed by 8 alphanumeric characters
22 - Example: C01X00T47, F20400481
24 The character set excludes visually ambiguous characters (I, O, Q, S, U)
25 as per ICAO Doc 9303 (Machine Readable Travel Documents) specifications.
27 :param patterns: List of patterns to be used by this recognizer
28 :param context: List of context words to increase confidence in detection
29 :param supported_language: Language this recognizer supports
30 :param supported_entity: The entity this recognizer can detect
31 """
33 PATTERNS = [
34 Pattern(
35 "Reisepassnummer (Strict ICAO charset)",
36 r"\b[CFGHJKLMNPRTVWXYZ][CFGHJKLMNPRTVWXYZ0-9]{7}[0-9]\b",
37 0.4,
38 ),
39 Pattern(
40 "Reisepassnummer (Relaxed)",
41 r"\b[A-Z][A-Z0-9]{7}[0-9]\b",
42 0.2,
43 ),
44 ]
46 CONTEXT = [
47 "reisepass",
48 "pass",
49 "passnummer",
50 "reisepassnummer",
51 "passport",
52 "passport number",
53 "pass-nr",
54 "dokumentennummer",
55 "bundesrepublik deutschland",
56 "ausweisdokument",
57 "mrz",
58 ]
60 def __init__(
61 self,
62 patterns: Optional[List[Pattern]] = None,
63 context: Optional[List[str]] = None,
64 supported_language: str = "de",
65 supported_entity: str = "DE_PASSPORT",
66 name: Optional[str] = None,
67 ):
68 patterns = patterns if patterns else self.PATTERNS
69 context = context if context else self.CONTEXT
70 super().__init__(
71 supported_entity=supported_entity,
72 patterns=patterns,
73 context=context,
74 supported_language=supported_language,
75 name=name,
76 )