Update explainers/explainer_algebra.py
Browse files- explainers/explainer_algebra.py +15 -59
explainers/explainer_algebra.py
CHANGED
|
@@ -1,59 +1,15 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|