Update explainers/explainer_percent.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849# explainer_percentimport refrom models import ExplainerResultdef explain_percent_question(text: str) -> ExplainerResult | None:t = text.lower()if "%" not in t and "percent" not in t:return None# basic detectionnumbers = re.findall(r'\d+', t)givens = []relationships = []if "of" in t:relationships.append("This is a part-of-whole relationship")if "%" in t:givens.append("A percentage is given")asks_for = Noneif "what is" in t or "find" in t:asks_for = "the unknown quantity (likely the whole or part)"return ExplainerResult(understood=True,topic="percent",asks_for=asks_for,givens=givens,constraints=[],relationships=relationships,needed_concepts=["percent equation (part = percent × whole)"],trap_notes=["Do not confuse the part and the whole","Check whether you are solving forward or backward"],strategy_hint="Translate the sentence into a percent equation before solving.",plain_english="The question describes a percentage relationship and is asking you to identify the missing value in that relationship.")12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182# explainer_percent.pyimport refrom models import ExplainerResultdef explain_percent_question(text: str) -> ExplainerResult | None:t = text.lower()has_percent = "%" in t or "percent" in t or "percentage" in tif not has_percent:return Nonegivens = []relationships = []constraints = []trap_notes = []percent_matches = re.findall(r"\b\d+(?:\.\d+)?%", t)number_matches = re.findall(r"\b\d+(?:\.\d+)?\b", t)if percent_matches:givens.append(f"A percentage is given: {', '.join(percent_matches[:3])}")else:givens.append("A percent relationship is given")if "of" in t:givens.append("The wording uses an 'of' relationship")if number_matches:givens.append(f"Numbers mentioned: {', '.join(number_matches[:5])}")relationships.append("This is a part-percent-whole relationship")if "of" in t:relationships.append("One quantity is being described as a percent of another quantity")if "increase" in t:relationships.append("The question may involve a percent increase from an original value")if "decrease" in t:relationships.append("The question may involve a percent decrease from an original value")if "original" in t or "whole" in t or "base" in t:constraints.append("Pay attention to which value is the original whole or base")if "more than" in t or "less than" in t:constraints.append("Watch the comparison wording carefully")asks_for = Noneif "original" in t or "whole" in t:asks_for = "the original whole value"elif "what percent" in t or "what percentage" in t:asks_for = "the missing percent"elif "what is" in t or "find" in t or "how much" in t:asks_for = "the missing value in the percent relationship"trap_notes.extend(["Do not confuse the part with the whole","Check whether you are solving for the percent, the part, or the whole","Make sure the percent is attached to the correct base value",])if "increase" in t or "decrease" in t:trap_notes.append("Do not mix up the original amount and the changed amount")return ExplainerResult(understood=True,topic="percent",asks_for=asks_for,givens=givens,constraints=constraints,relationships=relationships,needed_concepts=["percent equation","part-whole thinking","identifying the base value",],trap_notes=trap_notes,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.",plain_english="The question is describing a percent relationship and asking you to identify the missing value in that setup.",)
explainers/explainer_percent.py+81-48