Update custom_recognizers.py
This commit is contained in:
@@ -1,39 +1,47 @@
|
|||||||
from presidio_analyzer import Pattern, PatternRecognizer
|
from presidio_analyzer import Pattern, PatternRecognizer
|
||||||
|
|
||||||
# --- DÉTECTEURS BELGES ---
|
# --- DÉTECTEURS SPÉCIFIQUES À LA BELGIQUE ---
|
||||||
|
|
||||||
class BelgianNrnRecognizer(PatternRecognizer):
|
class BelgianNrnRecognizer(PatternRecognizer):
|
||||||
"""Détecteur pour le Numéro de Registre National belge."""
|
"""Détecteur pour le Numéro de Registre National belge (NRN/NISS)."""
|
||||||
PATTERNS = [Pattern(name="NRN", regex=r"\b(?:[0-9]{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12][0-9]|3[01]))-?\d{3}\.?\d{2}\b", score=1.0)]
|
PATTERNS = [Pattern(name="NRN (format standard)", regex=r"\b(?:[0-9]{2}\.[0-9]{2}\.[0-9]{2}-\d{3}\.\d{2})\b", score=1.0)]
|
||||||
CONTEXT = ["registre national", "nrn", "niss"]
|
CONTEXT = ["registre national", "nrn", "niss"]
|
||||||
SUPPORTED_ENTITY = "BE_NATIONAL_REGISTER_NUMBER"
|
SUPPORTED_ENTITY = "BE_NATIONAL_REGISTER_NUMBER"
|
||||||
|
|
||||||
class BelgianEnterpriseRecognizer(PatternRecognizer):
|
class BelgianEnterpriseRecognizer(PatternRecognizer):
|
||||||
"""Détecteur pour le N° d'entreprise belge."""
|
"""Détecteur pour le N° d'entreprise belge (BTW/TVA)."""
|
||||||
PATTERNS = [Pattern(name="BTW/TVA", regex=r"\bBE\s?0\d{3}\.\d{3}\.\d{3}\b", score=0.95)]
|
PATTERNS = [Pattern(name="BTW/TVA", regex=r"\bBE\s?0\d{3}\.\d{3}\.\d{3}\b", score=0.95)]
|
||||||
CONTEXT = ["numéro d'entreprise", "btw", "tva"]
|
CONTEXT = ["numéro d'entreprise", "btw", "tva"]
|
||||||
SUPPORTED_ENTITY = "BE_ENTERPRISE_NUMBER"
|
SUPPORTED_ENTITY = "BE_ENTERPRISE_NUMBER"
|
||||||
|
|
||||||
# --- DÉTECTEURS RGPD GÉNÉRIQUES ---
|
# --- AMÉLIORATIONS DES DÉTECTEURS DE BASE ---
|
||||||
|
|
||||||
class IbanRecognizer(PatternRecognizer):
|
class ImprovedIbanRecognizer(PatternRecognizer):
|
||||||
"""Détecteur pour les IBAN."""
|
"""Détecteur amélioré pour les IBAN, pour s'assurer qu'il est bien capturé."""
|
||||||
PATTERNS = [Pattern(name="IBAN", regex=r"\b[A-Z]{2}\d{2}\s?(?:\d{4}\s?){4,7}\d{1,4}\b", score=0.95)]
|
PATTERNS = [Pattern(name="IBAN", regex=r"\b[A-Z]{2}\d{2}(?:\s?\d{4}){3,7}(?:\s?\d{1,4})?\b", score=0.95)]
|
||||||
CONTEXT = ["iban", "compte", "bancaire"]
|
CONTEXT = ["iban", "compte", "bancaire", "virement"]
|
||||||
SUPPORTED_ENTITY = "IBAN"
|
SUPPORTED_ENTITY = "IBAN"
|
||||||
|
|
||||||
class PhoneRecognizer(PatternRecognizer):
|
class ImprovedPhoneRecognizer(PatternRecognizer):
|
||||||
"""Détecteur pour les numéros de téléphone EU."""
|
"""Détecteur amélioré pour les numéros de téléphone (BE/FR/LUX)."""
|
||||||
PATTERNS = [Pattern(name="Phone (EU)", regex=r"\b(?:(?:\+|00)(?:32|33|352)|0)\s?[1-9](?:[\s.-]?\d{2}){3,4}\b", score=0.8)]
|
PATTERNS = [Pattern(name="Phone (EU)", regex=r"\b(?:(?:\+|00)(?:32|33|352)|0)\s?[1-9](?:[\s.-]?\d{2}){3,4}\b", score=0.9)]
|
||||||
CONTEXT = ["tel", "téléphone", "gsm"]
|
CONTEXT = ["tel", "téléphone", "gsm", "mobile"]
|
||||||
SUPPORTED_ENTITY = "PHONE_NUMBER"
|
SUPPORTED_ENTITY = "PHONE_NUMBER"
|
||||||
|
|
||||||
# ... Ajoutez ici d'autres classes pour les autres regex si nécessaire ...
|
# --- NOUVEAUX DÉTECTEURS RGPD ---
|
||||||
|
|
||||||
# Liste de tous les reconnaisseurs à charger par Presidio
|
class FrenchNIRRecognizer(PatternRecognizer):
|
||||||
|
"""Détecteur pour le Numéro de Sécurité Sociale Français (NIR)."""
|
||||||
|
PATTERNS = [Pattern(name="NIR", regex=r"\b[12]\s?\d{2}\s?(?:0[1-9]|1[0-2])\s?(?:2[ABab]|[0-9]{2})\s?\d{3}\s?\d{3}\s?\d{2}\b", score=1.0)]
|
||||||
|
CONTEXT = ["sécurité sociale", "nir"]
|
||||||
|
SUPPORTED_ENTITY = "FR_SOCIAL_SECURITY_NUMBER"
|
||||||
|
|
||||||
|
# --- LISTE FINALE À CHARGER ---
|
||||||
|
# C'est cette liste que le config.yaml va importer.
|
||||||
custom_recognizers = [
|
custom_recognizers = [
|
||||||
BelgianNrnRecognizer,
|
BelgianNrnRecognizer,
|
||||||
BelgianEnterpriseRecognizer,
|
BelgianEnterpriseRecognizer,
|
||||||
IbanRecognizer,
|
ImprovedIbanRecognizer,
|
||||||
PhoneRecognizer,
|
ImprovedPhoneRecognizer,
|
||||||
|
FrenchNIRRecognizer,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user