Actualiser app.py
This commit is contained in:
20
app.py
20
app.py
@@ -11,7 +11,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Chargement du moteur Presidio via Provider
|
# Chargement du moteur
|
||||||
|
|
||||||
analyzer = None
|
analyzer = None
|
||||||
try:
|
try:
|
||||||
logger.info("--- Presidio Analyzer Service Starting ---")
|
logger.info("--- Presidio Analyzer Service Starting ---")
|
||||||
@@ -23,16 +24,19 @@ except Exception as e:
|
|||||||
logger.exception("Error during AnalyzerEngine initialization.")
|
logger.exception("Error during AnalyzerEngine initialization.")
|
||||||
analyzer = None
|
analyzer = None
|
||||||
|
|
||||||
# Regex strict pour IBAN belge format attendu
|
|
||||||
|
# Test Temporaire pour les Regex via du Python directement
|
||||||
|
|
||||||
IBAN_REGEX = re.compile(r"\b[A-Z]{2}[0-9]{2}(?:\s[0-9]{4}){3}\b", re.IGNORECASE)
|
IBAN_REGEX = re.compile(r"\b[A-Z]{2}[0-9]{2}(?:\s[0-9]{4}){3}\b", re.IGNORECASE)
|
||||||
|
|
||||||
# Regex IPv4
|
|
||||||
IPV4_REGEX = re.compile(
|
IPV4_REGEX = re.compile(
|
||||||
r"\b(?:(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)\.){3}"
|
r"\b(?:(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)\.){3}"
|
||||||
r"(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)\b"
|
r"(?:25[0-5]|2[0-4][0-9]|1\d{2}|[1-9]?\d)\b"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Liste des labels/phrases à exclure d’anonymisation (en minuscules)
|
# Liste Temporaire en surcouche des labels/phrases à exclure d’anonymisation
|
||||||
|
|
||||||
IGNORE_LABELS = {
|
IGNORE_LABELS = {
|
||||||
"témoins",
|
"témoins",
|
||||||
"témoins clés",
|
"témoins clés",
|
||||||
@@ -74,7 +78,8 @@ def analyze_text():
|
|||||||
logger.debug(f"Skipping anonymization of label: '{ent_text}'")
|
logger.debug(f"Skipping anonymization of label: '{ent_text}'")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Recadrage IBAN strict
|
# Recadrage IBAN
|
||||||
|
|
||||||
if res.entity_type == "IBAN":
|
if res.entity_type == "IBAN":
|
||||||
match = IBAN_REGEX.search(ent_text)
|
match = IBAN_REGEX.search(ent_text)
|
||||||
if match:
|
if match:
|
||||||
@@ -91,7 +96,8 @@ def analyze_text():
|
|||||||
logger.warning(f"Invalid IBAN detected, skipping: '{ent_text}'")
|
logger.warning(f"Invalid IBAN detected, skipping: '{ent_text}'")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Recadrage IP_ADDRESS strict IPv4 (wildcard possible pour IPv6 si besoin)
|
# Recadrage IP_ADDRESS
|
||||||
|
|
||||||
if res.entity_type == "IP_ADDRESS":
|
if res.entity_type == "IP_ADDRESS":
|
||||||
match = IPV4_REGEX.search(ent_text)
|
match = IPV4_REGEX.search(ent_text)
|
||||||
if match:
|
if match:
|
||||||
@@ -110,7 +116,7 @@ def analyze_text():
|
|||||||
|
|
||||||
filtered_results.append(res)
|
filtered_results.append(res)
|
||||||
|
|
||||||
# Retourner le résultat nettoyé
|
# Résultat nettoyé
|
||||||
response_data = [res.to_dict() for res in filtered_results]
|
response_data = [res.to_dict() for res in filtered_results]
|
||||||
return make_response(jsonify(response_data), 200)
|
return make_response(jsonify(response_data), 200)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user