Coverage for presidio_analyzer / predefined_recognizers / country_specific / italy / it_driver_license_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 ItDriverLicenseRecognizer(PatternRecognizer):
7 """
8 Recognizes IT Driver License 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 "Driver License",
19 (
20 r"\b(?i)(([A-Z]{2}\d{7}[A-Z])"
21 r"|(U1[BCDEFGHLJKMNPRSTUWYXZ0-9]{7}[A-Z]))\b"
22 ),
23 0.2,
24 ),
25 ]
26 CONTEXT = ["patente", "patente di guida", "licenza", "licenza di guida"]
28 def __init__(
29 self,
30 patterns: Optional[List[Pattern]] = None,
31 context: Optional[List[str]] = None,
32 supported_language: str = "it",
33 supported_entity: str = "IT_DRIVER_LICENSE",
34 name: Optional[str] = None,
35 ) -> None:
36 patterns = patterns if patterns else self.PATTERNS
37 context = context if context else self.CONTEXT
38 super().__init__(
39 supported_entity=supported_entity,
40 patterns=patterns,
41 context=context,
42 supported_language=supported_language,
43 name=name,
44 )