j-js commited on
Commit
99c40d6
·
verified ·
1 Parent(s): 9e67f64

Update explainers/explainer_algebra.py

Browse files
Files changed (1) hide show
  1. explainers/explainer_algebra.py +15 -59
explainers/explainer_algebra.py CHANGED
@@ -1,59 +1,15 @@
1
- import re
2
- from models import ExplainerResult
3
-
4
-
5
- def explain_algebra_question(text: str) -> ExplainerResult | None:
6
- t = text.lower()
7
-
8
- has_equation = "=" in t
9
- has_variable = bool(re.search(r"\b[a-z]\b", t))
10
- has_solve_word = "solve" in t or "value of" in t
11
-
12
- # Avoid stealing other topics
13
- if "%" in t or "percent" in t or "ratio" in t or re.search(r"\b\d+\s*:\s*\d+\b", t):
14
- return None
15
-
16
- if not (has_equation or has_variable or has_solve_word):
17
- return None
18
-
19
- givens = []
20
- relationships = []
21
- constraints = []
22
- trap_notes = []
23
-
24
- if has_equation:
25
- givens.append("An equation is given")
26
-
27
- variables = sorted(set(re.findall(r"\b[a-z]\b", t)))
28
- variables = [v for v in variables if v not in {"a", "i"}]
29
-
30
- if variables:
31
- givens.append(f"A variable appears: {', '.join(variables[:3])}")
32
-
33
- relationships.append("Both sides of the equation must remain equal")
34
- relationships.append("You need to isolate the variable")
35
-
36
- asks_for = "the value of the variable"
37
-
38
- trap_notes.extend([
39
- "Always perform operations on both sides of the equation",
40
- "Watch for sign errors",
41
- "Be careful with distributing brackets",
42
- ])
43
-
44
- return ExplainerResult(
45
- understood=True,
46
- topic="algebra",
47
- asks_for=asks_for,
48
- givens=givens,
49
- constraints=constraints,
50
- relationships=relationships,
51
- needed_concepts=[
52
- "inverse operations",
53
- "equation balancing",
54
- "isolating variables",
55
- ],
56
- trap_notes=trap_notes,
57
- strategy_hint="Undo operations step by step in reverse order to isolate the variable.",
58
- plain_english="The question gives an equation and asks you to isolate the variable to find its value.",
59
- )
 
1
+ from explainer_percent import explain_percent
2
+ from explainer_ratio import explain_ratio
3
+ from explainer_algebra import explain_algebra
4
+
5
+
6
+ def route_explainer(text: str):
7
+ for fn in (
8
+ explain_percent,
9
+ explain_ratio,
10
+ explain_algebra,
11
+ ):
12
+ result = fn(text)
13
+ if result is not None and getattr(result, "understood", False):
14
+ return result
15
+ return None