Enhance Exercise Retrieval and Path Handling Logic
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 48s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m23s

- Introduced new functions for handling exercise visibility and retrieval based on progression graph context, including `fetch_exercise_rows_by_ids_for_graph`.
- Updated `_load_supplemental_exercise_rows` to incorporate graph visibility rules, improving the accuracy of exercise retrieval.
- Enhanced `_run_path_step_retrieval` to utilize preloaded supplemental exercise rows, optimizing performance and clarity in path step processing.
- Added `exercise_title_equivalent_to_stage_goal` function to improve title matching against learning goals, enhancing exercise relevance.
- Updated tests to validate new retrieval logic and title equivalence functionality, ensuring robustness in exercise selection processes.
This commit is contained in:
Lars committed 2026-06-11 12:33:02 +02:00
1 parent ad051c015f
commit ca2adbd55e
8 files changed
+500 -81

No files matched your search

+46
View File
@@ -153,6 +153,48 @@ def _normalize_phrase(text: str) -> str:
return re.sub(r"\s+", " ", (text or "").strip().lower())
_STAGE_TITLE_STOP = frozenset(
{"für", "fur", "und", "der", "die", "das", "mit", "im", "in", "am", "an", "zur", "zum", "den", "dem", "des"}
)
def _stage_title_tokens(text: str) -> List[str]:
return [
tok
for tok in _normalize_phrase(text).split()
if tok not in _STAGE_TITLE_STOP and len(tok) > 1
]
def exercise_title_equivalent_to_stage_goal(title: str, learning_goal: str) -> bool:
"""
Titel entspricht dem Stufen-Lernziel (wortgleich oder nahezu identisch).
Deckt Graph-Slots ab, bei denen die Übung gezielt zum Lernziel angelegt wurde,
ohne dass die Pfad-Haupttechnik im Übungstext vorkommt.
"""
t = _normalize_phrase(title)
lg = _normalize_phrase(learning_goal)
if len(t) < 3 or len(lg) < 3:
return False
if t == lg:
return True
shorter, longer = (t, lg) if len(t) <= len(lg) else (lg, t)
if shorter in longer and len(shorter) >= 8 and len(shorter) / max(len(longer), 1) >= 0.72:
return True
t_tok = _stage_title_tokens(title)
lg_tok = _stage_title_tokens(learning_goal)
if len(t_tok) >= 2 and t_tok == lg_tok:
return True
if len(t_tok) >= 2 and len(lg_tok) >= 2:
t_set = set(t_tok)
lg_set = set(lg_tok)
overlap = len(t_set & lg_set)
if overlap >= 2 and overlap / max(len(t_set), len(lg_set)) >= 0.85:
return True
return False
def _normalize_query(text: str) -> str:
return re.sub(r"\s+", " ", (text or "").strip())
@@ -1059,6 +1101,9 @@ def exercise_passes_stage_fit(
if constraints.exclude_phrases and _blob_matches_stage_excludes(blob, constraints.exclude_phrases):
return False
if exercise_title_equivalent_to_stage_goal(title, learning_goal or lg):
return True
primary_path = (path_primary_topic or "").strip()
if not primary_path and lg:
hit = _find_technique_in_text(_normalize_phrase(lg))
@@ -1327,6 +1372,7 @@ __all__ = [
"build_stage_match_brief",
"enrich_brief_with_path_constraints",
"exercise_passes_stage_fit",
"exercise_title_equivalent_to_stage_goal",
"resolve_path_primary_topic",
"resolve_path_anti_patterns",
"exercise_passes_stage_learning_goal_gate",