new full
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import yaml
|
||||
import glob
|
||||
import re
|
||||
from typing import Dict, Any, List
|
||||
import logging
|
||||
|
||||
@@ -25,6 +26,8 @@ class ConfigLoader:
|
||||
for include_pattern in main_config['includes']:
|
||||
self._load_includes(include_pattern)
|
||||
|
||||
# Préprocesser les patterns du fichier principal aussi
|
||||
self._preprocess_regex_patterns(main_config)
|
||||
self._merge_config(main_config)
|
||||
|
||||
logger.info(f"Configuration chargée avec {len(self.config.get('recognizer_registry', {}).get('recognizers', []))} recognizers")
|
||||
@@ -41,11 +44,29 @@ class ConfigLoader:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
module_config = yaml.safe_load(f)
|
||||
if module_config:
|
||||
# Préprocesser les patterns regex pour gérer la ponctuation
|
||||
self._preprocess_regex_patterns(module_config)
|
||||
self._merge_config(module_config)
|
||||
logger.debug(f"Module chargé: {file_path}")
|
||||
except Exception as e:
|
||||
logger.error(f"Erreur lors du chargement de {file_path}: {e}")
|
||||
|
||||
def _preprocess_regex_patterns(self, config: Dict[str, Any]):
|
||||
"""Préprocesse les patterns regex pour gérer automatiquement la ponctuation"""
|
||||
if 'recognizer_registry' in config and 'recognizers' in config['recognizer_registry']:
|
||||
for recognizer in config['recognizer_registry']['recognizers']:
|
||||
if 'patterns' in recognizer:
|
||||
for pattern in recognizer['patterns']:
|
||||
if 'regex' in pattern:
|
||||
original_regex = pattern['regex']
|
||||
# Remplacer \b en fin de regex par un lookahead pour la ponctuation
|
||||
# Seulement si le pattern se termine par \b
|
||||
if original_regex.endswith('\\b'):
|
||||
# Enlever le \b final et ajouter le lookahead
|
||||
new_regex = original_regex[:-2] + '(?=\\s|[,.;:!?()]|$)'
|
||||
pattern['regex'] = new_regex
|
||||
logger.debug(f"Pattern modifié: {original_regex} -> {new_regex}")
|
||||
|
||||
def _merge_config(self, new_config: Dict[str, Any]):
|
||||
for key, value in new_config.items():
|
||||
if key == 'recognizer_registry':
|
||||
|
||||
Reference in New Issue
Block a user