Coverage for presidio_analyzer / predefined_recognizers / country_specific / india / in_voter_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 InVoterRecognizer(PatternRecognizer):
7 """
8 Recognize Indian Voter/Election Id(EPIC).
10 The Elector's Photo Identity Card or Voter id is a ten digit
11 alpha-numeric code issued by Election Commission of India
12 to adult domiciles who have reached the age of 18
13 Ref: https://en.wikipedia.org/wiki/Voter_ID_(India)
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 """
21 PATTERNS = [
22 Pattern(
23 "VOTER",
24 r"\b([A-Za-z]{1}[ABCDGHJKMNPRSYabcdghjkmnprsy]{1}[A-Za-z]{1}([0-9]){7})\b",
25 0.4,
26 ),
27 Pattern(
28 "VOTER",
29 r"\b([A-Za-z]){3}([0-9]){7}\b",
30 0.3,
31 ),
32 ]
34 CONTEXT = [
35 "voter",
36 "epic",
37 "elector photo identity card",
38 ]
40 def __init__(
41 self,
42 patterns: Optional[List[Pattern]] = None,
43 context: Optional[List[str]] = None,
44 supported_language: str = "en",
45 supported_entity: str = "IN_VOTER",
46 name: Optional[str] = None,
47 ):
48 patterns = patterns if patterns else self.PATTERNS
49 context = context if context else self.CONTEXT
50 super().__init__(
51 patterns=patterns,
52 context=context,
53 supported_language=supported_language,
54 supported_entity=supported_entity,
55 name=name,
56 )