From 223ff6bc61787c8a9e8b5420bc941dc94099b5ec Mon Sep 17 00:00:00 2001 From: Hugo Perrier Date: Fri, 4 Oct 2024 17:44:50 +0200 Subject: [PATCH] :sparkle: Add hooks to MelusineRegex --- melusine/base.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/melusine/base.py b/melusine/base.py index 9776863..98e5b68 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -487,6 +487,9 @@ def __call__(self, text: str) -> dict[str, Any]: Returns: _: Regex match results. """ + # Apply pre match hook + text = self.pre_match_hook(text) + match_dict = { self.MATCH_RESULT: False, self.NEUTRAL_MATCH_FIELD: {}, @@ -513,6 +516,9 @@ def __call__(self, text: str) -> dict[str, Any]: match_dict[self.MATCH_RESULT] = positive_match and not negative_match + # Apply post match hook + match_dict = self.post_match_hook(match_dict) + return match_dict def describe(self, text: str, position: bool = False) -> None: