30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
"""ZP Wiki -> CRZP: which ZP Wiki person a question names.
|
|
|
|
The combined answer (tools/answers/combined.py) asks CRZP for exactly that
|
|
person (the canonical wiki name) at Technická univerzita v Košiciach.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
|
|
def wiki_person(question: str, db_file=None) -> str | None:
|
|
"""The one ZP Wiki person the question names (canonical name), else None."""
|
|
match = wiki_match(question, db_file)
|
|
return match["name"] if match else None
|
|
|
|
|
|
def wiki_match(question: str, db_file=None) -> dict | None:
|
|
"""{"name", "student"}: the one ZP Wiki person the question names; student = has a profile page."""
|
|
from tools.answers.question_plan import planning_catalog
|
|
from tools.rag.common import DB_FILE
|
|
from tools.retrieval.person_names import resolve_person_names
|
|
try:
|
|
catalog = planning_catalog(db_file or DB_FILE)
|
|
except (OSError, ValueError, RuntimeError):
|
|
return None
|
|
resolution = resolve_person_names(question, catalog or [])
|
|
matches = resolution.get("matches") or []
|
|
if resolution.get("status") != "ok" or len({m["name"] for m in matches}) != 1:
|
|
return None
|
|
source = matches[0].get("source_document") or ""
|
|
return {"name": matches[0]["name"], "student": source.startswith(("pages/students/", "pages/interns/"))}
|