Delete presidio_config directory
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
"""
|
||||
Configuration personnalisée pour Presidio avec support français/belge.
|
||||
"""
|
||||
|
||||
__version__ = "1.0.0"
|
||||
__author__ = "Votre équipe"
|
||||
@@ -1,118 +0,0 @@
|
||||
# =====================================================================
|
||||
# CONFIGURATION PRESIDIO POUR DOCUMENTS FRANÇAIS/BELGES
|
||||
# =====================================================================
|
||||
|
||||
# Configuration du moteur de langage (NLP)
|
||||
nlp_engine_name: spacy
|
||||
supported_languages: [en, fr]
|
||||
models:
|
||||
- lang_code: en
|
||||
model_name: en_core_web_lg
|
||||
- lang_code: fr
|
||||
model_name: fr_core_news_sm
|
||||
|
||||
# Configuration du comportement du moteur NLP
|
||||
ner_model_configuration:
|
||||
labels_to_ignore:
|
||||
- MISC
|
||||
- ORG # Éviter les faux positifs sur les noms d'organisations
|
||||
|
||||
# Seuils de confiance par entité
|
||||
confidence_threshold:
|
||||
default: 0.35
|
||||
EMAIL_ADDRESS: 0.5
|
||||
PHONE_NUMBER: 0.6
|
||||
PERSON: 0.7
|
||||
|
||||
# Configuration des détecteurs (Recognizers)
|
||||
recognizer_registry:
|
||||
# Charger d'abord les détecteurs par défaut
|
||||
- default
|
||||
# Puis ajouter nos détecteurs personnalisés
|
||||
- presidio_config.custom_recognizers.custom_recognizers
|
||||
|
||||
# Liste des mots à ignorer (faux positifs courants)
|
||||
allow_list:
|
||||
# Termes contractuels génériques
|
||||
- Contrat
|
||||
- contrat
|
||||
- Contrats
|
||||
- Document
|
||||
- document
|
||||
- Société
|
||||
- Investisseur
|
||||
- Montant
|
||||
- Prêt
|
||||
- Intérêt
|
||||
- Intérêts
|
||||
- Partie
|
||||
- Parties
|
||||
- Annexe
|
||||
- Remboursement
|
||||
- Conversion
|
||||
- Financement
|
||||
- Sortie
|
||||
- "Juste Valeur Marchande"
|
||||
- Échéance
|
||||
- Clause
|
||||
- Clauses
|
||||
- Principe
|
||||
- Coûts
|
||||
- Notifications
|
||||
- Article
|
||||
- Paragraphe
|
||||
- Directeur
|
||||
- Gérant
|
||||
- Président
|
||||
# Termes financiers courants
|
||||
- Euro
|
||||
- EUR
|
||||
- Euros
|
||||
- Pourcentage
|
||||
- Taux
|
||||
- Valeur
|
||||
- Prix
|
||||
- Montant
|
||||
# Termes juridiques
|
||||
- Loi
|
||||
- Code
|
||||
- Règlement
|
||||
- Décret
|
||||
- Arrêté
|
||||
# Mois et dates génériques
|
||||
- Janvier
|
||||
- Février
|
||||
- Mars
|
||||
- Avril
|
||||
- Mai
|
||||
- Juin
|
||||
- Juillet
|
||||
- Août
|
||||
- Septembre
|
||||
- Octobre
|
||||
- Novembre
|
||||
- Décembre
|
||||
|
||||
# Configuration des transformations d'anonymisation
|
||||
anonymizer_config:
|
||||
# Remplacements par défaut
|
||||
default_anonymizers:
|
||||
PERSON: replace
|
||||
EMAIL_ADDRESS: replace
|
||||
PHONE_NUMBER: replace
|
||||
BE_NATIONAL_REGISTER_NUMBER: replace
|
||||
BE_ENTERPRISE_NUMBER: replace
|
||||
FR_SOCIAL_SECURITY_NUMBER: replace
|
||||
IBAN: replace
|
||||
BE_BANK_ACCOUNT: replace
|
||||
|
||||
# Valeurs de remplacement personnalisées
|
||||
replacements:
|
||||
PERSON: "<PERSONNE>"
|
||||
EMAIL_ADDRESS: "<EMAIL>"
|
||||
PHONE_NUMBER: "<TELEPHONE>"
|
||||
BE_NATIONAL_REGISTER_NUMBER: "<NRN_BELGE>"
|
||||
BE_ENTERPRISE_NUMBER: "<NUM_ENTREPRISE_BE>"
|
||||
FR_SOCIAL_SECURITY_NUMBER: "<NUM_SECU_FR>"
|
||||
IBAN: "<IBAN>"
|
||||
BE_BANK_ACCOUNT: "<COMPTE_BANCAIRE_BE>"
|
||||
@@ -1,40 +0,0 @@
|
||||
# Configuration de l'analyseur principal Presidio
|
||||
supported_languages:
|
||||
- en
|
||||
- fr
|
||||
|
||||
# Seuil de score par défaut
|
||||
default_score_threshold: 0.35
|
||||
|
||||
# Configuration du registre des reconnaisseurs
|
||||
recognizer_registry:
|
||||
supported_languages:
|
||||
- en
|
||||
- fr
|
||||
global_regex_flags: 26
|
||||
|
||||
# Configuration des entités supportées
|
||||
supported_entities:
|
||||
- PERSON
|
||||
- EMAIL_ADDRESS
|
||||
- PHONE_NUMBER
|
||||
- ORGANIZATION
|
||||
- LOCATION
|
||||
- DATE_TIME
|
||||
- URL
|
||||
- IP_ADDRESS
|
||||
- CREDIT_CARD
|
||||
- CRYPTO
|
||||
- IBAN_CODE
|
||||
- US_SSN
|
||||
- US_PASSPORT
|
||||
- US_DRIVER_LICENSE
|
||||
|
||||
# Configuration des seuils de confiance par entité
|
||||
entity_threshold:
|
||||
PERSON: 0.6
|
||||
EMAIL_ADDRESS: 0.4
|
||||
PHONE_NUMBER: 0.5
|
||||
ORGANIZATION: 0.7
|
||||
LOCATION: 0.6
|
||||
DATE_TIME: 0.5
|
||||
@@ -1,191 +0,0 @@
|
||||
"""
|
||||
Reconnaisseurs personnalisés pour les données belges et françaises.
|
||||
"""
|
||||
|
||||
from presidio_analyzer import Pattern, PatternRecognizer
|
||||
|
||||
|
||||
class BelgianNrnRecognizer(PatternRecognizer):
|
||||
"""Détecteur pour le Numéro de Registre National belge (NRN/NISS)."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="NRN format standard",
|
||||
regex=r"\b\d{2}\.\d{2}\.\d{2}-\d{3}\.\d{2}\b",
|
||||
score=1.0
|
||||
),
|
||||
Pattern(
|
||||
name="NRN format compact",
|
||||
regex=r"\b\d{11}\b",
|
||||
score=0.7
|
||||
),
|
||||
Pattern(
|
||||
name="NRN format espacé",
|
||||
regex=r"\b\d{2}\s\d{2}\s\d{2}\s\d{3}\s\d{2}\b",
|
||||
score=0.9
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="BE_NATIONAL_REGISTER_NUMBER",
|
||||
patterns=patterns,
|
||||
context=["registre national", "nrn", "niss", "numéro national", "identité"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class BelgianEnterpriseRecognizer(PatternRecognizer):
|
||||
"""Détecteur pour le numéro d'entreprise belge (BTW/TVA)."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="BTW/TVA format standard",
|
||||
regex=r"\bBE\s?0\d{3}\.\d{3}\.\d{3}\b",
|
||||
score=0.95
|
||||
),
|
||||
Pattern(
|
||||
name="BTW/TVA format compact",
|
||||
regex=r"\bBE\s?0\d{9}\b",
|
||||
score=0.9
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="BE_ENTERPRISE_NUMBER",
|
||||
patterns=patterns,
|
||||
context=["numéro d'entreprise", "btw", "tva", "entreprise", "société"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class BelgianBankAccountRecognizer(PatternRecognizer):
|
||||
"""Détecteur pour les comptes bancaires belges."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="Compte bancaire belge",
|
||||
regex=r"\b\d{3}-\d{7}-\d{2}\b",
|
||||
score=0.9
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="BE_BANK_ACCOUNT",
|
||||
patterns=patterns,
|
||||
context=["compte", "bancaire", "virement", "domiciliation", "banque"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class ImprovedIbanRecognizer(PatternRecognizer):
|
||||
"""Détecteur amélioré pour les IBAN européens."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="IBAN avec espaces",
|
||||
regex=r"\b[A-Z]{2}\d{2}(?:\s\d{4}){3,7}(?:\s\d{1,4})?\b",
|
||||
score=0.95
|
||||
),
|
||||
Pattern(
|
||||
name="IBAN compact",
|
||||
regex=r"\b[A-Z]{2}\d{2}[A-Z0-9]{4,32}\b",
|
||||
score=0.9
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="IBAN",
|
||||
patterns=patterns,
|
||||
context=["iban", "compte", "bancaire", "virement", "international"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class ImprovedPhoneRecognizer(PatternRecognizer):
|
||||
"""Détecteur amélioré pour les numéros de téléphone BE/FR/LUX."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="Téléphone international",
|
||||
regex=r"\b(?:\+|00)(?:32|33|352)\s?[1-9](?:[\s.-]?\d{2}){3,4}\b",
|
||||
score=0.9
|
||||
),
|
||||
Pattern(
|
||||
name="Téléphone national",
|
||||
regex=r"\b0[1-9](?:[\s.-]?\d{2}){4}\b",
|
||||
score=0.8
|
||||
),
|
||||
Pattern(
|
||||
name="Mobile belge",
|
||||
regex=r"\b04\d{2}[\s.-]?\d{2}[\s.-]?\d{2}[\s.-]?\d{2}\b",
|
||||
score=0.85
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="PHONE_NUMBER",
|
||||
patterns=patterns,
|
||||
context=["tel", "téléphone", "gsm", "mobile", "portable", "numéro"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class FrenchNIRRecognizer(PatternRecognizer):
|
||||
"""Détecteur pour le Numéro de Sécurité Sociale français (NIR)."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="NIR avec espaces",
|
||||
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
|
||||
),
|
||||
Pattern(
|
||||
name="NIR compact",
|
||||
regex=r"\b[12]\d{2}(?:0[1-9]|1[0-2])(?:2[ABab]|[0-9]{2})\d{6}\d{2}\b",
|
||||
score=0.95
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="FR_SOCIAL_SECURITY_NUMBER",
|
||||
patterns=patterns,
|
||||
context=["sécurité sociale", "nir", "numéro social", "sécu"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
class ImprovedEmailRecognizer(PatternRecognizer):
|
||||
"""Détecteur d'email amélioré avec contexte français."""
|
||||
|
||||
def __init__(self):
|
||||
patterns = [
|
||||
Pattern(
|
||||
name="Email standard",
|
||||
regex=r"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b",
|
||||
score=0.9
|
||||
)
|
||||
]
|
||||
super().__init__(
|
||||
supported_entity="EMAIL_ADDRESS",
|
||||
patterns=patterns,
|
||||
context=["email", "mail", "courriel", "adresse électronique", "e-mail", "@"],
|
||||
supported_language="fr"
|
||||
)
|
||||
|
||||
|
||||
# Fonction pour créer les instances des reconnaisseurs
|
||||
def get_custom_recognizers():
|
||||
"""Retourne la liste des reconnaisseurs personnalisés instanciés."""
|
||||
return [
|
||||
BelgianNrnRecognizer(),
|
||||
BelgianEnterpriseRecognizer(),
|
||||
BelgianBankAccountRecognizer(),
|
||||
ImprovedIbanRecognizer(),
|
||||
ImprovedPhoneRecognizer(),
|
||||
FrenchNIRRecognizer(),
|
||||
ImprovedEmailRecognizer()
|
||||
]
|
||||
|
||||
|
||||
# Variable pour la compatibilité avec la configuration YAML
|
||||
custom_recognizers = get_custom_recognizers()
|
||||
@@ -1,66 +0,0 @@
|
||||
import os
|
||||
from presidio_analyzer import AnalyzerEngine, RecognizerRegistry
|
||||
from presidio_analyzer.nlp_engine import SpacyNlpEngine
|
||||
from presidio_analyzer.predefined_recognizers import EmailRecognizer, IbanRecognizer, PhoneRecognizer, CreditCardRecognizer, DateRecognizer, UrlRecognizer, IpRecognizer
|
||||
from presidio_config.custom_recognizers import custom_recognizers as my_custom_rules
|
||||
|
||||
# Cette classe est une adaptation pour lancer le serveur Flask de Presidio avec Gunicorn
|
||||
from gunicorn.app.base import BaseApplication
|
||||
|
||||
# 1. Créer le moteur NLP pour le français
|
||||
nlp_engine = SpacyNlpEngine(models={"fr": "fr_core_news_sm"})
|
||||
|
||||
# 2. Créer le registre des règles
|
||||
registry = RecognizerRegistry()
|
||||
|
||||
# 3. Charger les règles par défaut que nous voulons IMPÉRATIVEMENT
|
||||
# C'est ici que nous forçons le chargement du détecteur d'emails
|
||||
registry.load_predefined_recognizers(
|
||||
languages=["fr"],
|
||||
recognizers=[
|
||||
EmailRecognizer,
|
||||
DateRecognizer,
|
||||
PhoneRecognizer,
|
||||
UrlRecognizer,
|
||||
IpRecognizer,
|
||||
CreditCardRecognizer,
|
||||
]
|
||||
)
|
||||
|
||||
# 4. Ajouter nos règles personnalisées par-dessus
|
||||
registry.add_recognizers(my_custom_rules)
|
||||
|
||||
# 5. Créer le moteur d'analyse final avec notre registre personnalisé
|
||||
analyzer_engine = AnalyzerEngine(nlp_engine=nlp_engine, registry=registry)
|
||||
|
||||
# 6. Préparer l'application Flask de Presidio
|
||||
from presidio_analyzer.main import app
|
||||
app.config["analyzer_engine"] = analyzer_engine
|
||||
|
||||
# 7. Définir une classe pour lancer Gunicorn
|
||||
class StandaloneApplication(BaseApplication):
|
||||
def __init__(self, app, options=None):
|
||||
self.options = options or {}
|
||||
self.application = app
|
||||
super().__init__()
|
||||
|
||||
def load_config(self):
|
||||
config = {
|
||||
key: value
|
||||
for key, value in self.options.items()
|
||||
if key in self.cfg.settings and value is not None
|
||||
}
|
||||
for key, value in config.items():
|
||||
self.cfg.set(key.lower(), value)
|
||||
|
||||
def load(self):
|
||||
return self.application
|
||||
|
||||
# 8. Point de démarrage du serveur
|
||||
if __name__ == "__main__":
|
||||
options = {
|
||||
"bind": "%s:%s" % ("0.0.0.0", "3000"),
|
||||
"workers": int(os.environ.get("GUNICORN_WORKERS", "1")),
|
||||
"threads": int(os.environ.get("GUNICORN_THREADS", "1")),
|
||||
}
|
||||
StandaloneApplication(app, options).run()
|
||||
Reference in New Issue
Block a user