From 827cf03aac2cf0282a53f645c4bc70ae00e105e4 Mon Sep 17 00:00:00 2001 From: Aarav Navani Date: Fri, 30 Aug 2024 15:59:49 -0700 Subject: [PATCH] local inference case issues --- validator/main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/validator/main.py b/validator/main.py index 9e63141..d0fbae1 100644 --- a/validator/main.py +++ b/validator/main.py @@ -246,7 +246,8 @@ def filter_output_in_sentence(self, sentence: str, competitors: List[str]) -> st filtered_text = sentence for competitor in competitors: - filtered_text = filtered_text.replace(competitor, "[COMPETITOR]") + pattern = re.compile(re.escape(competitor), re.IGNORECASE) + filtered_text = pattern.sub("[COMPETITOR]", filtered_text) return filtered_text @@ -259,12 +260,10 @@ def compute_error_spans(self, sentences: List[str], competitors_per_sentence: Li for competitor in competitors: - start_idx = 0 - while sentence.find(competitor, start_idx) > -1: - start_idx = sentence.find(competitor, start_idx) - end_idx = start_idx + len(competitor) + pattern = re.compile(re.escape(competitor), re.IGNORECASE) + for match in pattern.finditer(sentence): + start_idx, end_idx = match.span() error_spans.append(ErrorSpan(start=start_idx, end=end_idx, reason=f"Competitor was found: {competitor}")) - start_idx = end_idx return error_spans