j-js commited on
Commit
7a2d839
·
verified ·
1 Parent(s): 928da19

Update explainers/explainer_percent.py

Browse files
Files changed (1) hide show
  1. explainers/explainer_percent.py +81 -48
explainers/explainer_percent.py CHANGED
@@ -1,49 +1,82 @@
1
- # explainer_percent
2
-
3
- import re
4
- from models import ExplainerResult
5
-
6
- def explain_percent_question(text: str) -> ExplainerResult | None:
7
- t = text.lower()
8
-
9
- if "%" not in t and "percent" not in t:
10
- return None
11
-
12
- # basic detection
13
- numbers = re.findall(r'\d+', t)
14
-
15
- givens = []
16
- relationships = []
17
-
18
- if "of" in t:
19
- relationships.append("This is a part-of-whole relationship")
20
-
21
- if "%" in t:
22
- givens.append("A percentage is given")
23
-
24
- asks_for = None
25
- if "what is" in t or "find" in t:
26
- asks_for = "the unknown quantity (likely the whole or part)"
27
-
28
- return ExplainerResult(
29
- understood=True,
30
- topic="percent",
31
-
32
- asks_for=asks_for,
33
- givens=givens,
34
- constraints=[],
35
-
36
- relationships=relationships,
37
- needed_concepts=[
38
- "percent equation (part = percent × whole)"
39
- ],
40
-
41
- trap_notes=[
42
- "Do not confuse the part and the whole",
43
- "Check whether you are solving forward or backward"
44
- ],
45
-
46
- strategy_hint="Translate the sentence into a percent equation before solving.",
47
-
48
- plain_english="The question describes a percentage relationship and is asking you to identify the missing value in that relationship."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  )
 
1
+ # explainer_percent.py
2
+
3
+ import re
4
+ from models import ExplainerResult
5
+
6
+
7
+ def explain_percent_question(text: str) -> ExplainerResult | None:
8
+ t = text.lower()
9
+
10
+ has_percent = "%" in t or "percent" in t or "percentage" in t
11
+ if not has_percent:
12
+ return None
13
+
14
+ givens = []
15
+ relationships = []
16
+ constraints = []
17
+ trap_notes = []
18
+
19
+ percent_matches = re.findall(r"\b\d+(?:\.\d+)?%", t)
20
+ number_matches = re.findall(r"\b\d+(?:\.\d+)?\b", t)
21
+
22
+ if percent_matches:
23
+ givens.append(f"A percentage is given: {', '.join(percent_matches[:3])}")
24
+ else:
25
+ givens.append("A percent relationship is given")
26
+
27
+ if "of" in t:
28
+ givens.append("The wording uses an 'of' relationship")
29
+
30
+ if number_matches:
31
+ givens.append(f"Numbers mentioned: {', '.join(number_matches[:5])}")
32
+
33
+ relationships.append("This is a part-percent-whole relationship")
34
+
35
+ if "of" in t:
36
+ relationships.append("One quantity is being described as a percent of another quantity")
37
+
38
+ if "increase" in t:
39
+ relationships.append("The question may involve a percent increase from an original value")
40
+
41
+ if "decrease" in t:
42
+ relationships.append("The question may involve a percent decrease from an original value")
43
+
44
+ if "original" in t or "whole" in t or "base" in t:
45
+ constraints.append("Pay attention to which value is the original whole or base")
46
+
47
+ if "more than" in t or "less than" in t:
48
+ constraints.append("Watch the comparison wording carefully")
49
+
50
+ asks_for = None
51
+ if "original" in t or "whole" in t:
52
+ asks_for = "the original whole value"
53
+ elif "what percent" in t or "what percentage" in t:
54
+ asks_for = "the missing percent"
55
+ elif "what is" in t or "find" in t or "how much" in t:
56
+ asks_for = "the missing value in the percent relationship"
57
+
58
+ trap_notes.extend([
59
+ "Do not confuse the part with the whole",
60
+ "Check whether you are solving for the percent, the part, or the whole",
61
+ "Make sure the percent is attached to the correct base value",
62
+ ])
63
+
64
+ if "increase" in t or "decrease" in t:
65
+ trap_notes.append("Do not mix up the original amount and the changed amount")
66
+
67
+ return ExplainerResult(
68
+ understood=True,
69
+ topic="percent",
70
+ asks_for=asks_for,
71
+ givens=givens,
72
+ constraints=constraints,
73
+ relationships=relationships,
74
+ needed_concepts=[
75
+ "percent equation",
76
+ "part-whole thinking",
77
+ "identifying the base value",
78
+ ],
79
+ trap_notes=trap_notes,
80
+ strategy_hint="First decide which number is the whole, which is the part, and whether the question is asking you to work forward or backward.",
81
+ plain_english="The question is describing a percent relationship and asking you to identify the missing value in that setup.",
82
  )