dp-zp-agent/tools/answer_evaluation/question_intent.py

43 lines
2.0 KiB
Python

"""Explicit answer aspects; these select evidence, never supply facts."""
import re
from .context_policy import normalized
FACET_PATTERNS = {
'assignment': r'\b(?:zadani\w*|ciel\w*)\b',
'plans': r'\b(?:planovan\w*|dalsi\w*\s+uloh\w*|uloh\w*)\b',
'problems': r'\b(?:problem\w*|tazkost\w*|prekazk\w*|chyb\w*)\b',
'methods': r'\b(?:metod\w*|technolog\w*|nastroj\w*|pouziv\w*|pouzil\w*)\b',
'experiments': r'\b(?:experiment\w*|merani\w*|testovani\w*|vyhodnocov\w*)\b',
'progress':r'\b(?:priebezn\w*\s+)?stav\w*\b',
'results': r'\b(?:vysledk\w*|dosiahn\w*)\b',
}
FACET_LABELS = {'assignment': 'Zadanie a ciele', 'plans':'Plánované úlohy', 'problems': 'Riešené problémy',
'methods': 'Metódy a technológie', 'experiments': 'Experimenty a vyhodnotenie',
'progress':'Priebežný stav','results': 'Zaznamenané výsledky'}
def requested_facets(question: str) -> list[str]:
text = normalized(re.sub(r'[„“"«][^„“”"»]+[“”"»]', ' ', question))
matches = [(m.start(), key) for key, pattern in FACET_PATTERNS.items()
if (m := re.search(pattern, text))]
return [key for _, key in sorted(matches)]
def content_question(question: str) -> bool:
text = normalized(question)
return bool(requested_facets(question) or re.search(
r'\b(?:comu|o com|obsah\w*|opis\w*|popis\w*|zamer\w*|zhrn\w*|implement\w*)\b', text))
def facet_mode(question: str) -> bool:
facets = requested_facets(question)
return any(facet in facets for facet in ['plans','progress','problems','methods','experiments','results'])
def planned_experiments(question: str) -> bool:
text=normalized(question)
if re.search(r'\b(?:vykonal\w*|vykonan\w*|uskutocnil\w*|uskutocnen\w*|realizoval\w*|realizovan\w*|otestoval\w*|vyhodnotil\w*)\b',text):
return False
return bool(re.search(r'\b(?:plan\w*|pripravit|navrhnut)|'
r'\b(?:mal|mali|mala|ma|maju)\s+(?:priprav\w*|navrhn\w*|otest\w*|vyhodnot\w*)',text))