Externalize dictionaries and add anonymization review corpus
This commit is contained in:
@@ -48,33 +48,16 @@ try:
|
||||
except Exception:
|
||||
yaml = None
|
||||
|
||||
APP_TITLE = "Pseudonymisation de PDF"
|
||||
DEFAULT_CFG = Path("config/dictionnaires.yml")
|
||||
from config_defaults import (
|
||||
RUNTIME_DICTIONARIES_CONFIG_PATH,
|
||||
read_default_dictionaries_text,
|
||||
read_runtime_dictionaries_overlay_text,
|
||||
)
|
||||
|
||||
DEFAULTS_CFG_TEXT = r"""
|
||||
# dictionnaires.yml – valeurs par défaut (bloc littéral pour les regex)
|
||||
version: 1
|
||||
encoding: "utf-8"
|
||||
normalization: "NFKC"
|
||||
whitelist:
|
||||
sections_titres: [DIM, GHM, GHS, RUM, COMPTE, RENDU, DIAGNOSTIC]
|
||||
noms_maj_excepts: ["Médecin DIM", "Praticien conseil"]
|
||||
org_gpe_keep: true
|
||||
blacklist:
|
||||
force_mask_terms: []
|
||||
force_mask_regex: []
|
||||
kv_labels_preserve: [FINESS, IPP, "N° OGC", Etablissement]
|
||||
regex_overrides:
|
||||
- name: OGC_court
|
||||
pattern: |-
|
||||
\b(?:N°\s*)?OGC\s*[:\-]?\s*([A-Za-z0-9\-]{1,3})\b
|
||||
placeholder: '[OGC]'
|
||||
flags: [IGNORECASE]
|
||||
flags:
|
||||
case_insensitive: true
|
||||
unicode_word_boundaries: true
|
||||
regex_engine: "python"
|
||||
"""
|
||||
APP_TITLE = "Pseudonymisation de PDF"
|
||||
DEFAULT_CFG = RUNTIME_DICTIONARIES_CONFIG_PATH
|
||||
DEFAULTS_CFG_TEXT = read_default_dictionaries_text()
|
||||
RUNTIME_CFG_TEXT = read_runtime_dictionaries_overlay_text()
|
||||
|
||||
|
||||
class ToolTip:
|
||||
@@ -208,7 +191,7 @@ class App:
|
||||
# YAML helpers
|
||||
def _ensure_cfg_exists(self):
|
||||
p = Path(self.cfg_path.get()); p.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not p.exists(): p.write_text(DEFAULTS_CFG_TEXT, encoding="utf-8")
|
||||
if not p.exists(): p.write_text(RUNTIME_CFG_TEXT, encoding="utf-8")
|
||||
def _cfg_browse(self):
|
||||
d = filedialog.asksaveasfilename(defaultextension=".yml", filetypes=[("YAML","*.yml *.yaml"), ("Tous","*.*")])
|
||||
if d: self.cfg_path.set(d)
|
||||
@@ -225,14 +208,14 @@ class App:
|
||||
if yaml is None:
|
||||
messagebox.showerror("PyYAML manquant", "Installez PyYAML (pip install pyyaml)."); return
|
||||
try:
|
||||
Path(self.cfg_path.get()).write_text(yaml.safe_dump(self.cfg_data or yaml.safe_load(DEFAULTS_CFG_TEXT), allow_unicode=True, sort_keys=False), encoding="utf-8")
|
||||
Path(self.cfg_path.get()).write_text(yaml.safe_dump(self.cfg_data or {}, allow_unicode=True, sort_keys=False), encoding="utf-8")
|
||||
self._log("Règles sauvegardées.")
|
||||
except Exception as e:
|
||||
messagebox.showerror("Erreur", f"Impossible d'écrire le YAML: {e}")
|
||||
def _reload_cfg(self): self._load_cfg(); self._log("Règles rechargées.")
|
||||
def _restore_defaults(self):
|
||||
try:
|
||||
Path(self.cfg_path.get()).write_text(DEFAULTS_CFG_TEXT, encoding="utf-8"); self._log("CFG par défaut écrit."); self._load_cfg()
|
||||
Path(self.cfg_path.get()).write_text(RUNTIME_CFG_TEXT, encoding="utf-8"); self._log("Surcharge locale réinitialisée."); self._load_cfg()
|
||||
except Exception as e:
|
||||
messagebox.showerror("Erreur", f"Impossible d'écrire le YAML par défaut: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user