Update explainers/explainer_ratio.py
Browse files- explainers/explainer_ratio.py +17 -22
explainers/explainer_ratio.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# explainer_ratio.py
|
| 2 |
-
|
| 3 |
import re
|
| 4 |
from models import ExplainerResult
|
| 5 |
|
|
@@ -7,6 +5,7 @@ from models import ExplainerResult
|
|
| 7 |
def explain_ratio_question(text: str) -> ExplainerResult | None:
|
| 8 |
t = text.lower()
|
| 9 |
|
|
|
|
| 10 |
has_ratio_word = "ratio" in t or "proportion" in t
|
| 11 |
has_ratio_form = bool(re.search(r"\b\d+\s*:\s*\d+\b", t))
|
| 12 |
|
|
@@ -19,33 +18,29 @@ def explain_ratio_question(text: str) -> ExplainerResult | None:
|
|
| 19 |
trap_notes = []
|
| 20 |
|
| 21 |
ratio_matches = re.findall(r"\b\d+\s*:\s*\d+\b", t)
|
|
|
|
| 22 |
if ratio_matches:
|
| 23 |
givens.append(f"A ratio is given: {', '.join(ratio_matches[:3])}")
|
| 24 |
else:
|
| 25 |
-
givens.append("A
|
| 26 |
|
| 27 |
-
if "total" in t:
|
| 28 |
-
givens.append("A total amount may
|
| 29 |
|
| 30 |
-
|
| 31 |
-
relationships.append("This is comparing one group to another group")
|
| 32 |
-
else:
|
| 33 |
-
relationships.append("This is a fixed proportional relationship between quantities")
|
| 34 |
|
| 35 |
-
if "
|
| 36 |
-
relationships.append("You may need to
|
| 37 |
|
| 38 |
-
if "
|
| 39 |
-
|
| 40 |
|
| 41 |
-
asks_for =
|
| 42 |
-
if "what is" in t or "find" in t or "how many" in t:
|
| 43 |
-
asks_for = "the missing part or total in the ratio relationship"
|
| 44 |
|
| 45 |
trap_notes.extend([
|
| 46 |
-
"Do not confuse part-to-part ratios with part-to-whole
|
| 47 |
"Keep the ratio order consistent",
|
| 48 |
-
"If a total is given, first find
|
| 49 |
])
|
| 50 |
|
| 51 |
return ExplainerResult(
|
|
@@ -57,10 +52,10 @@ def explain_ratio_question(text: str) -> ExplainerResult | None:
|
|
| 57 |
relationships=relationships,
|
| 58 |
needed_concepts=[
|
| 59 |
"ratio structure",
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
],
|
| 63 |
trap_notes=trap_notes,
|
| 64 |
-
strategy_hint="
|
| 65 |
-
plain_english="The question is describing a ratio
|
| 66 |
)
|
|
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
from models import ExplainerResult
|
| 3 |
|
|
|
|
| 5 |
def explain_ratio_question(text: str) -> ExplainerResult | None:
|
| 6 |
t = text.lower()
|
| 7 |
|
| 8 |
+
# STRONG detection
|
| 9 |
has_ratio_word = "ratio" in t or "proportion" in t
|
| 10 |
has_ratio_form = bool(re.search(r"\b\d+\s*:\s*\d+\b", t))
|
| 11 |
|
|
|
|
| 18 |
trap_notes = []
|
| 19 |
|
| 20 |
ratio_matches = re.findall(r"\b\d+\s*:\s*\d+\b", t)
|
| 21 |
+
|
| 22 |
if ratio_matches:
|
| 23 |
givens.append(f"A ratio is given: {', '.join(ratio_matches[:3])}")
|
| 24 |
else:
|
| 25 |
+
givens.append("A proportional relationship is described")
|
| 26 |
|
| 27 |
+
if "total" in t or "class" in t:
|
| 28 |
+
givens.append("A total amount may be relevant")
|
| 29 |
|
| 30 |
+
relationships.append("This is a fixed proportional relationship between quantities")
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
if "fraction" in t or "what fraction" in t:
|
| 33 |
+
relationships.append("You may need to convert a ratio into a fraction of the whole")
|
| 34 |
|
| 35 |
+
if "boys to girls" in t or "men to women" in t:
|
| 36 |
+
relationships.append("This compares two groups within a total")
|
| 37 |
|
| 38 |
+
asks_for = "a missing part, total, or fraction from the ratio"
|
|
|
|
|
|
|
| 39 |
|
| 40 |
trap_notes.extend([
|
| 41 |
+
"Do not confuse part-to-part ratios with part-to-whole fractions",
|
| 42 |
"Keep the ratio order consistent",
|
| 43 |
+
"If a total is given, first find the total number of ratio parts",
|
| 44 |
])
|
| 45 |
|
| 46 |
return ExplainerResult(
|
|
|
|
| 52 |
relationships=relationships,
|
| 53 |
needed_concepts=[
|
| 54 |
"ratio structure",
|
| 55 |
+
"proportional scaling",
|
| 56 |
+
"part-to-whole conversion",
|
| 57 |
],
|
| 58 |
trap_notes=trap_notes,
|
| 59 |
+
strategy_hint="Work out how many total parts the ratio represents, then map that to the quantity you need.",
|
| 60 |
+
plain_english="The question is describing a ratio between quantities and asking you to find a missing part or convert it into a fraction of the whole.",
|
| 61 |
)
|