j-js commited on
Commit
3a0ff5a
·
verified ·
1 Parent(s): 0e143c5

Create explainer_ratio.py

Browse files
Files changed (1) hide show
  1. explainers/explainer_ratio.py +66 -0
explainers/explainer_ratio.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # explainer_ratio.py
2
+
3
+ import re
4
+ from models import ExplainerResult
5
+
6
+
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
+
13
+ if not has_ratio_word and not has_ratio_form:
14
+ return None
15
+
16
+ givens = []
17
+ relationships = []
18
+ constraints = []
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 ratio or proportional relationship is given")
26
+
27
+ if "total" in t:
28
+ givens.append("A total amount may also be given")
29
+
30
+ if "boys to girls" in t or "men to women" in t or "part to part" in t:
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 "total" in t:
36
+ relationships.append("You may need to connect ratio parts to a whole total")
37
+
38
+ if "remaining" in t or "left" in t:
39
+ constraints.append("Pay attention to what remains after a change")
40
+
41
+ asks_for = None
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 relationships",
47
+ "Keep the ratio order consistent",
48
+ "If a total is given, first find how many equal parts the ratio contains",
49
+ ])
50
+
51
+ return ExplainerResult(
52
+ understood=True,
53
+ topic="ratio",
54
+ asks_for=asks_for,
55
+ givens=givens,
56
+ constraints=constraints,
57
+ relationships=relationships,
58
+ needed_concepts=[
59
+ "ratio structure",
60
+ "part-to-part or part-to-whole setup",
61
+ "equal scaling of ratio parts",
62
+ ],
63
+ trap_notes=trap_notes,
64
+ strategy_hint="Decide whether the ratio compares two parts or links parts to a total before setting anything up.",
65
+ plain_english="The question is describing a ratio relationship and asking you to identify a missing part or total from that proportional setup.",
66
+ )