-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm.py
More file actions
29 lines (22 loc) · 744 Bytes
/
llm.py
File metadata and controls
29 lines (22 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from presidio_analyzer import AnalyzerEngine
class EnglishDLPAnalyzer:
def __init__(self):
self.analyzer = AnalyzerEngine()
def analyze_text(self, text: str):
"""
Returns:
{
"is_leak": bool,
"entities": ["EMAIL_ADDRESS", "PHONE_NUMBER", ...]
}
"""
if not text or text.strip() == "":
return {"is_leak": False, "entities": []}
results = self.analyzer.analyze(text=text, language="en")
if not results:
return {"is_leak": False, "entities": []}
entities = list(set([r.entity_type for r in results]))
return {
"is_leak": True,
"entities": entities
}