Skip to content

Commit 5ecfe07

Browse files
authored
Italian Driver License Recognizer Fix (#1651)
1 parent 18a7f87 commit 5ecfe07

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All notable changes to this project will be documented in this file.
44

55
## [unreleased]
6+
### Analyzer
7+
#### Changed
8+
- Implement Fix for Italian Duplicate Driver license
9+
- Update Test cases to account for changed recognizer
610

711
## [2.2.359] - 2025-07-06
812
### Analyzer

presidio-analyzer/presidio_analyzer/predefined_recognizers/it_driver_license_recognizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ItDriverLicenseRecognizer(PatternRecognizer):
1818
"Driver License",
1919
(
2020
r"\b(?i)(([A-Z]{2}\d{7}[A-Z])"
21-
r"|(^[U]1[BCDEFGHLMNPRSTUWYXZ]\w{6}[A-Z]))\b"
21+
r"|(^[U]1[BCDEFGHLJKMNPRSTUWYXZ0-9]{7}[A-Z]))\b"
2222
),
2323
0.2,
2424
),
@@ -31,7 +31,7 @@ def __init__(
3131
context: Optional[List[str]] = None,
3232
supported_language: str = "it",
3333
supported_entity: str = "IT_DRIVER_LICENSE",
34-
):
34+
) -> None:
3535
patterns = patterns if patterns else self.PATTERNS
3636
context = context if context else self.CONTEXT
3737
super().__init__(

presidio-analyzer/tests/test_it_driver_license_recognizer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66

77
@pytest.fixture(scope="module")
8-
def recognizer():
8+
def recognizer() -> ItDriverLicenseRecognizer:
99
return ItDriverLicenseRecognizer()
1010

1111

1212
@pytest.fixture(scope="module")
13-
def entities():
13+
def entities() -> list[str]:
1414
return ["IT_DRIVER_LICENSE"]
1515

1616

@@ -25,8 +25,10 @@ def entities():
2525
2,
2626
((0, 10), (15, 25),),
2727
((0.1, 0.4), (0.1, 0.4),),),
28-
# Test with old Driver License
29-
("U1H00A000B", 1, ((0, 10),), ((0.1, 0.4),),),
28+
# Test with valid duplicate Driver License
29+
("U1H00B000C", 1, ((0, 10),), ((0.1, 0.4),),),
30+
# Test with invalid duplicate Driver License
31+
("U1H00A000B", 0, (), (),),
3032
# Test with invalid Driver License
3133
("990123456B", 0, (), (),),
3234
# fmt: on
@@ -40,7 +42,7 @@ def test_when_driver_licenses_in_text_then_all_it_driver_licenses_found(
4042
recognizer,
4143
entities,
4244
max_score,
43-
):
45+
) -> None:
4446
results = recognizer.analyze(text, entities)
4547
assert len(results) == expected_len
4648
for res, (st_pos, fn_pos), (st_score, fn_score) in zip(

0 commit comments

Comments
 (0)