File size: 4,555 Bytes
59d9f71 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | """
solution_loader.py
------------------
SAFE priority-aware solution loader.
IMPORTANT:
- Returns a FLAT LIST (engine contract unchanged)
- Internally reorders solutions by intent priority
- Normalizes instructional solutions to match engine's 'situations' expectation
"""
# ----------------------------
# Existing solution libraries
# ----------------------------
from solutions.solutions import SOLUTIONS # MAIN SOLUTIONS LIBRARY
from solutions.behavior_solutions import BEHAVIOR_SOLUTIONS
from solutions.management_solutions import MANAGEMENT_SOLUTIONS
from solutions.wellbeing_solutions import WELLBEING_SOLUTIONS
from solutions.productivity_solutions import PRODUCTIVITY_SOLUTIONS
from solutions.inclusive_solutions import INCLUSIVE_SOLUTIONS
from solutions.fln_solutions import FLN_SOLUTIONS
from solutions.reddit_based_solutions import REDDIT_SOLUTIONS
from solutions.science_solutions import SCIENCE_SOLUTIONS
# ----------------------------
# Instructional libraries
# ----------------------------
from instructional_concept_library.math.solutions import MATH_INSTRUCTIONAL_SOLUTIONS
from instructional_concept_library.science.solutions import SCIENCE_INSTRUCTIONAL_SOLUTIONS
from instructional_concept_library.language.solutions import LANGUAGE_INSTRUCTIONAL_SOLUTIONS
from instructional_concept_library.social_studies.solutions import SOCIAL_STUDIES_INSTRUCTIONAL_SOLUTIONS
def _is_diagnostic(solution: dict) -> bool:
return solution.get("instruction_type") == "DIAGNOSTIC"
def _normalize_instructional_solution(sol: dict) -> dict:
"""
Injects 'situations' key into instructional solutions
so the Engine can score them correctly.
"""
# Create situations list if missing
if "situations" not in sol:
sol["situations"] = []
# 1. Map 'student_profile' (e.g., CONCEPT_CONFUSION) to situations
if "student_profile" in sol:
sol["situations"].extend(sol["student_profile"])
# 2. Map 'topic' (e.g., GEOMETRY_2D_3D) to situations
# This allows the engine to match specific topics detected in text
if "topic" in sol:
sol["situations"].append(sol["topic"])
return sol
def load_solutions():
"""
Returns a SINGLE flat list of solutions,
ordered by priority to guide the engine naturally.
Priority order:
1. Instructional (subject-specific)
2. Diagnostic (subject-specific)
3. Behavioral / Management
4. Wellbeing
5. Other support solutions
"""
instructional = []
diagnostic = []
behavioral = []
wellbeing = []
other = []
# --------------------------------------------------
# Instructional Concept Libraries (HIGH PRIORITY)
# --------------------------------------------------
# Helper to process and sort into lists
def process_lib(library):
for sol in library:
# Normalize first!
norm_sol = _normalize_instructional_solution(sol)
if _is_diagnostic(norm_sol):
diagnostic.append(norm_sol)
else:
instructional.append(norm_sol)
process_lib(MATH_INSTRUCTIONAL_SOLUTIONS)
process_lib(SCIENCE_INSTRUCTIONAL_SOLUTIONS)
process_lib(LANGUAGE_INSTRUCTIONAL_SOLUTIONS)
process_lib(SOCIAL_STUDIES_INSTRUCTIONAL_SOLUTIONS)
# --------------------------------------------------
# Behavioral / Management (MID PRIORITY)
# --------------------------------------------------
behavioral.extend(BEHAVIOR_SOLUTIONS)
behavioral.extend(MANAGEMENT_SOLUTIONS)
# --------------------------------------------------
# Wellbeing (LOW PRIORITY)
# --------------------------------------------------
wellbeing.extend(WELLBEING_SOLUTIONS)
# --------------------------------------------------
# Other Supporting Libraries (LOWEST PRIORITY)
# --------------------------------------------------
other.extend(SOLUTIONS) # MAIN SOLUTIONS LIBRARY
other.extend(PRODUCTIVITY_SOLUTIONS)
other.extend(INCLUSIVE_SOLUTIONS)
other.extend(FLN_SOLUTIONS)
other.extend(REDDIT_SOLUTIONS)
other.extend(SCIENCE_SOLUTIONS)
# --------------------------------------------------
# FINAL MERGED LIST (FLAT, ORDERED)
# --------------------------------------------------
return (
instructional
+ diagnostic
+ behavioral
+ wellbeing
+ other
) |