99
1010from datafog .engine import scan , scan_and_redact
1111from datafog .models .anonymizer import AnonymizerType
12+ from datafog .processing .text_processing .regex_annotator import RegexAnnotator
1213
1314# Engine types as constants
1415REGEX_ENGINE = "regex"
1516SPACY_ENGINE = "spacy"
1617AUTO_ENGINE = "auto"
1718
1819
19- def detect_pii (text : str ) -> Dict [str , List [str ]]:
20+ def detect_pii (
21+ text : str ,
22+ locales : List [str ] | None = None ,
23+ ) -> Dict [str , List [str ]]:
2024 """
2125 Simple PII detection using lightweight regex engine.
2226
@@ -37,7 +41,7 @@ def detect_pii(text: str) -> Dict[str, List[str]]:
3741
3842 try :
3943 # Use engine boundary for canonical scan behavior.
40- scan_result = scan (text = text , engine = REGEX_ENGINE )
44+ scan_result = scan (text = text , engine = REGEX_ENGINE , locales = locales )
4145 pii_dict : Dict [str , List [str ]] = {}
4246 for entity in scan_result .entities :
4347 if not entity .text .strip ():
@@ -81,7 +85,11 @@ def detect_pii(text: str) -> Dict[str, List[str]]:
8185 ) from e
8286
8387
84- def anonymize_text (text : str , method : Union [str , AnonymizerType ] = "redact" ) -> str :
88+ def anonymize_text (
89+ text : str ,
90+ method : Union [str , AnonymizerType ] = "redact" ,
91+ locales : List [str ] | None = None ,
92+ ) -> str :
8593 """
8694 Simple text anonymization using lightweight regex engine.
8795
@@ -120,6 +128,7 @@ def anonymize_text(text: str, method: Union[str, AnonymizerType] = "redact") ->
120128 text = text ,
121129 engine = REGEX_ENGINE ,
122130 strategy = strategy_map [method ],
131+ locales = locales ,
123132 )
124133
125134 try :
@@ -155,7 +164,9 @@ def anonymize_text(text: str, method: Union[str, AnonymizerType] = "redact") ->
155164
156165
157166def scan_text (
158- text : str , return_entities : bool = False
167+ text : str ,
168+ return_entities : bool = False ,
169+ locales : List [str ] | None = None ,
159170) -> Union [bool , Dict [str , List [str ]]]:
160171 """
161172 Quick scan to check if text contains any PII.
@@ -180,7 +191,7 @@ def scan_text(
180191
181192 _start = _time .monotonic ()
182193
183- entities = detect_pii (text )
194+ entities = detect_pii (text , locales = locales )
184195
185196 result = entities if return_entities else len (entities ) > 0
186197
@@ -200,7 +211,7 @@ def scan_text(
200211 return result
201212
202213
203- def get_supported_entities () -> List [str ]:
214+ def get_supported_entities (locales : List [ str ] | None = None ) -> List [str ]:
204215 """
205216 Get list of PII entity types supported by the regex engine.
206217
@@ -210,17 +221,15 @@ def get_supported_entities() -> List[str]:
210221 Example:
211222 >>> entities = get_supported_entities()
212223 >>> print(entities)
213- ['EMAIL', 'PHONE', 'SSN', 'CREDIT_CARD', 'IP_ADDRESS', 'DOB ', 'ZIP ']
224+ ['EMAIL', 'PHONE', 'SSN', 'CREDIT_CARD', 'IP_ADDRESS', 'DE_VAT_ID ', 'DE_IBAN', 'DATE', 'ZIP_CODE ']
214225 """
215- result = [
216- "EMAIL" ,
217- "PHONE" ,
218- "SSN" ,
219- "CREDIT_CARD" ,
220- "IP_ADDRESS" ,
221- "DATE" ,
222- "ZIP_CODE" ,
223- ]
226+ annotator = RegexAnnotator (locales = locales )
227+ legacy_map = {"DOB" : "DATE" , "ZIP" : "ZIP_CODE" }
228+ result = []
229+ for label in annotator .active_labels :
230+ canonical = legacy_map .get (label , label )
231+ if canonical not in result :
232+ result .append (canonical )
224233
225234 try :
226235 from datafog .telemetry import track_function_call
0 commit comments