úlohy v otázkach na detail práce, rozpor roku wiki a CRZP, zoznam s počtom v CRZP, test číta všetky strany

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ján Pták 2026-11-24 17:19:00 +01:00
parent f426621296
commit 578a29ba07
6 changed files with 93 additions and 8 deletions

View File

@ -815,3 +815,24 @@ def test_a_rejected_answer_about_a_student_the_register_does_not_know_is_answere
assert result["status"] == "ok" and "Orchestrácia" in result["answer"]
other = C.compose("Akú architektúru trénoval Ján Pták?", "Akú architektúru trénoval Ján Pták?", "rag", dict(REJECTED), None, "Ján Pták")
assert other["status"] == "error"
def test_who_in_the_wiki_and_how_many_in_the_register_are_two_questions(combo):
question = "Kto sa v ZP Wiki venuje téme chatbot a koľko prác o nej je v CRZP?"
assert C.list_and_count(question) == ["Kto sa v ZP Wiki venuje téme chatbot?", "Koľko prác o téme chatbot je v CRZP?"]
assert C.list_and_count("Ktorí Hládkovi študenti robili s Kubernetes, aké mali práce a koľko prác o Kubernetes je v CRZP?") is None
asked = []
def deliver(q, **kw):
asked.append(q)
if q.startswith("Kto"):
text = "**1. Ján Pták** chatbot\n\nZdroje: https://zp.test/jan\n\nNašli sa ešte 3 ďalšie osoby. Chceš vidieť ďalšie?"
else:
text = "Počet prác (téma „chatbot“): **233**.\n\nZdroje: https://opac.test/1"
return {**WIKI, "answer": text}
combo["deliver"] = deliver
result = ask(combo, question)
text = result["answer"]
assert asked == ["Kto sa v ZP Wiki venuje téme chatbot?", "Koľko prác o téme chatbot je v CRZP?"]
assert text.index("Ján Pták") < text.index("233") and text.rstrip().endswith("Chceš vidieť ďalšie?")
assert text.count("Zdroje:") == 1

View File

@ -179,3 +179,11 @@ def test_the_work_a_student_is_doing_is_the_newest_wiki_thesis(theses):
assert asked.get("options") # no present tense: which thesis?
finally:
U.person_works = old
def test_a_year_the_register_and_the_wiki_give_differently_is_said_with_both():
work = {"type": "bachelor_thesis", "year": 2020, "source": "wiki", "row": {"year": 2021}}
assert U.year_note(work) == " (v ZP Wiki je pri práci uvedený rok 2020)"
assert U.year_note({**work, "row": {"year": 2020}}) == "" # the same year: nothing added
assert U.year_note({**work, "type": "bachelor_project"}) == "" # a project has no defence year
assert U.year_note({"type": "bachelor_thesis", "year": 2021, "source": "crzp", "row": {"year": 2021}}) == ""

View File

@ -30,6 +30,7 @@ from scoring import check, failure_point, last_branch # noqa: E402
from static_tags import tags # noqa: E402
TIMINGS = ROOT / "data" / "logs" / "answer_timings.jsonl"
MORE = "Chceš vidieť ďalšie?"
def _env(name: str) -> str:
@ -106,7 +107,19 @@ def run_case(case: dict, base: str) -> dict:
**diagnostics(result)})
if result.get("status") == "request_error":
break
return {"result": result, "steps": steps, "seconds": round(time.time() - started, 1)}
# A list shown in pages is read to its end with "áno", as a user would (and as the gold set does): its names
# on later pages are part of the answer.
pages = 1
while MORE in (result.get("answer") or "") and token and pages < 20 and result.get("status") != "request_error":
try:
more = ask(base, "áno", case["engine"], token)
except Exception:
break
token = (more.get("conversation_context") or {}).get("token") or token
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
return {"result": result, "steps": steps, "seconds": round(time.time() - started, 1), "pages": pages}
def main(argv=None) -> int:
@ -161,7 +174,8 @@ def main(argv=None) -> int:
"delivery": {k: (ran["result"].get("delivery_check") or {}).get(k) for k in ("layer", "code")},
"negative": bool(case.get("negative")), "compound": bool(case.get("compound")),
"expect": case.get("expect"), "answer": (ran["result"].get("answer") or "")[:2500],
"source_urls": (ran["result"].get("source_urls") or [])[:12], "steps": ran["steps"]}
"source_urls": (ran["result"].get("source_urls") or [])[:12], "pages": ran.get("pages", 1),
"steps": ran["steps"]}
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
handle.flush()
passed += row["pass"]

View File

@ -435,6 +435,23 @@ def work_and_meeting(question: str, named: dict | None) -> list[str] | None:
return [re.sub(r"\s*[?.!]*\s*$", "", first) + "?", second]
# "Kto sa v ZP Wiki venuje téme chatbot a koľko prác o nej je v CRZP?": who in the wiki, and the register's count
LIST_AND_COUNT = re.compile(r"^(?P<first>.*?\bvenuj\w*\s+tem\w*\s+(?P<topic>.+?))\s+a\s+kolko\s+prac\w*\s+o\s+"
r"(?:nej|tejto\s+teme|nom)\s+(?:je|existuje)\s+v\s+(?:crzp|registri\w*)\W*$")
def list_and_count(question: str) -> list[str] | None:
"""["Kto sa v ZP Wiki venuje téme chatbot?", "Koľko prác o téme chatbot je v CRZP?"] for the question joining both."""
from tools.answers.planning.noise import fold_chars
text = question.strip()
match = LIST_AND_COUNT.match(fold_chars(text))
if not match:
return None
first = text[:match.end("first")].strip(" ,")
topic = text[match.start("topic"):match.end("topic")].strip(" ,„“\"")
return [first + "?", f"Koľko prác o téme {topic} je v CRZP?"]
def _two_answers(question: str, parts: list[str], *, engine, limit, complete, deliver) -> dict | None:
"""One answer of the parts of a question, in their order, with one source line; None when a part has no
answer (the question then goes the usual way)."""
@ -443,14 +460,19 @@ def _two_answers(question: str, parts: list[str], *, engine, limit, complete, de
if not all(r.get("status") == "ok" and r.get("accepted_for_delivery") is True and isinstance(r.get("answer"), str)
for r in results):
return None
bodies, urls = [], []
bodies, urls, more, kept = [], [], "", {}
for result in results:
body, found = split_sources(result["answer"])
offer = re.search(r"\n*(Našl\w* sa ešte [^\n]*Chceš vidieť ďalšie\?)\s*$", body)
if offer and not more: # a list shown in pages: its offer goes last, its context (the rest) stays
more, body = offer.group(1), body[:offer.start()].rstrip()
kept = unseal((result.get("conversation_context") or {}).get("token")) or {}
bodies.append(body)
urls += found or list(result.get("source_urls") or [])
urls = list(dict.fromkeys(urls))[:MAX_SOURCES]
text = "\n\n".join(bodies) + ("\n\nZdroje: " + ", ".join(urls) if urls else "")
return _with_token(_ok(question, engine, text, urls, results[0]), question=question)
text = "\n\n".join(bodies) + ("\n\nZdroje: " + ", ".join(urls) if urls else "") + ("\n\n" + more if more else "")
return _with_token(_ok(question, engine, text, urls, results[0]), question=question,
page=kept.get("page"), entities=kept.get("entities") or ())
# a past-tense verb without its subject ("použil", "robila", "mal"), in a question that is not "kto …?"
@ -1805,7 +1827,7 @@ def _answer(question: str, *, engine: str, limit: int, context_token: str | None
named = _one_person(question) if words else None
if named:
_subject.set(named["name"])
parts = None if (previous or {}).get("options") else work_and_meeting(question, named)
parts = None if (previous or {}).get("options") else (work_and_meeting(question, named) or list_and_count(question))
if parts: # "Aká je bakalárska práca X a čo robil na poslednom stretnutí?": both parts, in their order
both = _two_answers(question, parts, engine=engine, limit=limit, complete=complete, deliver=deliver)
if both is not None:

View File

@ -64,6 +64,11 @@ class Condition(Strict):
kind: Literal['tag','category','document_author','quantity','exclusion','current_status','year_verification','other']
quote: str
# "mala použiť", "má naštudovať", "mal vyskúšať": a task given to the student (Úlohy), not a recorded result
MODAL_TASK = re.compile(r"\b(?:mal[aoiy]?|ma|maju)\s+(?:[a-z]+\s+){0,4}?(?:pouzit|vyskusat|skusit|preskumat|skumat|nastudovat|"
r"pouzivat|nasadit|otestovat|vyhodnotit|pridat|napisat|spustit|aktivovat|precitat|naucit|zistit|ziskat)\b")
class MeetingRequest(Strict):
selection: Literal['latest','exact','all']
ids: list[str] = Field(default_factory=list, max_length=12)
@ -189,6 +194,11 @@ def direct_spec(question, resolution, *, meeting=None, route=None, relative_year
if not facets and (mode=='meeting' or route is not None and route.type=='meeting') and re.search(
r'\b(?:riesil\w*|riesi|robil\w*|urobil\w*|spravil\w*|stihol\w*|stihla|pracoval\w*|dosiahol\w*|dosiahla|dokoncil\w*)\b',n):
facets=['progress'] # "Čo riešil na stretnutí?": what was done (status, results), not the new tasks
if facets and MODAL_TASK.search(n) and 'plans' not in facets or not facets and route is not None and route.facets \
and MODAL_TASK.search(n):
# "Aké webové rozhranie mala X použiť?", "Aký model mala vyskúšať podľa zadania?": what X was to do is a task
# of the records (Úlohy), kept besides the facets already asked
facets=[*(facets or list(route.facets)),'plans']
global_discovery=discovery_question(q)
if route is None and mode not in {'similar','supervisor','advisors','completion','meeting','period','proposal'} and global_discovery:
mode='discovery'

View File

@ -415,6 +415,15 @@ def defended(work: dict):
return row.get("year") if row.get("year") and work["type"] in THESES else work.get("year")
def year_note(work: dict) -> str:
"""" (v ZP Wiki je pri práci uvedený rok 2020)" when the register's year of a thesis is another than the wiki's."""
own = work.get("wiki_year", work.get("year") if work.get("source") == "wiki" else None)
shown = defended(work)
if work["type"] not in THESES or not own or not shown or own == shown:
return ""
return f" (v ZP Wiki je pri práci uvedený rok {own})"
def register_title(work: dict) -> str | None:
"""The register's title of the work when it differs from the one in ZP Wiki."""
title, own = (work.get("row") or {}).get("title"), work.get("wiki_title", work.get("title"))
@ -426,7 +435,8 @@ def of_kind(works: list[dict], kinds) -> list[dict]:
2021: Dialógový systém…" = the bachelor thesis 2022 in CRZP) is that thesis, with the register's year."""
kinds = [kinds] if isinstance(kinds, str) else list(kinds)
out = [w if w["type"] in kinds else {**w, "type": w["thesis"], "year": w["row"].get("year") or w.get("year"),
"title": w["row"].get("title") or w.get("title"), "wiki_title": w.get("title")}
"title": w["row"].get("title") or w.get("title"), "wiki_title": w.get("title"),
"wiki_year": w.get("year") if w.get("source") == "wiki" else None}
for w in works if w["type"] in kinds or w.get("thesis") in kinds]
return sorted(out, key=lambda w: -(w.get("year") or 0))
@ -747,7 +757,7 @@ def work_card(person: str, works: list[dict], low: str, wiki_text: str = "") ->
people = _role_people(person, work, aspect, wiki_text)
lines.append(f"- {CARD_LABEL[aspect]}: {join(people) if people else 'v podkladoch nie je uvedený'}")
elif aspect == "year":
lines.append(f"- Rok: {defended(work)}" if defended(work) else "- Rok: v podkladoch nie je")
lines.append(f"- Rok: {defended(work)}{year_note(work)}" if defended(work) else "- Rok: v podkladoch nie je")
elif aspect == "school":
school = row.get("school") or ("Technická univerzita v Košiciach" if work["source"] == "wiki" else None)
lines.append(f"- Škola: {school}" + (" (FEI, KEMT)" if work["source"] == "wiki" else "")