From 4a0dc506d0e6211da342604d23aef83198525621 Mon Sep 17 00:00:00 2001 From: jp170na Date: Tue, 24 Nov 2026 18:34:42 +0100 Subject: [PATCH] =?UTF-8?q?hodnotenie=20testov:=20meno=20len=20ako=20s?= =?UTF-8?q?=C3=BAvisl=C3=A9=20slov=C3=A1,=20u=C5=BE=C5=A1ie=20odmietnutie,?= =?UTF-8?q?=20str=C3=A1nky=20bez=20nov=C3=A9ho=20tokenu=20kon=C4=8Dia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- test/rule_trace/run.py | 2 +- test/rule_trace/scoring.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/test/rule_trace/run.py b/test/rule_trace/run.py index ef44b5a..06180e3 100644 --- a/test/rule_trace/run.py +++ b/test/rule_trace/run.py @@ -115,7 +115,7 @@ def run_case(case: dict, base: str) -> dict: more = ask(base, "áno", case["engine"], token) except Exception: break - token = (more.get("conversation_context") or {}).get("token") or token + token = (more.get("conversation_context") or {}).get("token") # no new token: the list has no further page result = {**result, "answer": (result.get("answer") or "").replace(MORE, "") + "\n\n" + (more.get("answer") or ""), "source_urls": list(dict.fromkeys([*(result.get("source_urls") or []), *(more.get("source_urls") or [])]))} pages += 1 diff --git a/test/rule_trace/scoring.py b/test/rule_trace/scoring.py index 8eee5cb..fdb1b9b 100644 --- a/test/rule_trace/scoring.py +++ b/test/rule_trace/scoring.py @@ -25,25 +25,29 @@ REFUSAL = re.compile(r"nie je uveden|nie je v podkladoch|v podkladoch nie|taky u r"neexist|nie je zaznamenan|nie su zaznamenan|nemozem|neviem|ziadn|nie je dostupn|upresn|ktor\w+ mysli|" r"nie je mozne|nepotvrdzujem|neuvadza|nie je zname|nie je evidovan|odpovedam len|nie je doloz|" r"skontroluj meno|uved cele meno|nie je isté|nie je iste|nema v podkladoch|nemaju v podkladoch|" - r"klucove slovo [^.;]{1,60}? nema\b|\bnemaju\b|nespomina|nesplna|v podkladoch nie su") + r"klucove slovo [^.;]{1,60}? nema\b|\bnemaju\s+spolocn|\bspolocn\w*(?:\s+\w+){0,4}\s+nemaju\b|nespomina|nesplna|" + r"v podkladoch nie su") def fold(text: str | None) -> str: return " ".join(unicodedata.normalize("NFKD", text or "").encode("ascii", "ignore").decode().lower().split()) -NAME = re.compile(r"^[A-ZÁ-Ž][^\W\d_]+(?:\s+[A-ZÁ-Ž][^\W\d_]+){1,2}$") +def is_name(phrase: str) -> bool: + """Two or three words, each capitalized and only letters ("Martin Šarišský", "Denis Le Thanh").""" + words = phrase.split() + return 2 <= len(words) <= 3 and all(w.isalpha() and w[0].isupper() for w in words) def contains(phrase: str, text: str) -> bool: """The phrase in the folded text; a person's name also in another case ("Martina Šarišského" for - "Martin Šarišský"): every word's stem starts a word of the text.""" + "Martin Šarišský"): the words' stems next to each other, in order (never words of two other people).""" if fold(phrase) in text: return True - if not NAME.match(phrase.strip()): + if not is_name(phrase.strip()): return False - stems = [fold(w)[:max(4, len(w) - 2)] for w in phrase.split()] - return all(re.search(rf"\b{re.escape(stem)}", text) for stem in stems) + stems = [fold(w)[:max(4, len(fold(w)) - 2)] for w in phrase.split()] + return bool(re.search(r"\b" + r"\w*\s+".join(re.escape(stem) for stem in stems) + r"\w*\b", text)) def check(case: dict, result: dict) -> dict: