39 lines
1.7 KiB
Python
39 lines
1.7 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',
|
|
'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',
|
|
'results': r'\b(?:vysledk\w*|dosiahn\w*|stav\w*)\b',
|
|
}
|
|
FACET_LABELS = {'assignment': 'Zadanie a ciele', 'problems': 'Riešené problémy',
|
|
'methods': 'Metódy a technológie', 'experiments': 'Experimenty a vyhodnotenie',
|
|
'results': 'Zaznamenaný stav a 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 ['problems','methods','experiments','results'])
|
|
|
|
|
|
def planned_experiments(question: str) -> bool:
|
|
text=normalized(question)
|
|
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))
|