Spaces:
Running
Running
| import re | |
| class QuestionType: | |
| PERCENT = "percent" | |
| RATIO = "ratio" | |
| ALGEBRA = "algebra" | |
| STATISTICS = "statistics" | |
| PROBABILITY = "probability" | |
| GEOMETRY = "geometry" | |
| ARITHMETIC = "arithmetic" | |
| UNKNOWN = "unknown" | |
| def detect_question_type(question_text: str) -> str: | |
| q = question_text.lower() | |
| if "%" in q or "percent" in q or "increase" in q or "decrease" in q: | |
| return QuestionType.PERCENT | |
| if "ratio" in q or ":" in q or "proportion" in q: | |
| return QuestionType.RATIO | |
| if re.search(r"\bmean\b|\bmedian\b|\bmode\b|\bstandard deviation\b", q): | |
| return QuestionType.STATISTICS | |
| if "probability" in q or "chance" in q or "random" in q: | |
| return QuestionType.PROBABILITY | |
| if "triangle" in q or "circle" in q or "radius" in q or "area" in q: | |
| return QuestionType.GEOMETRY | |
| if re.search(r"[a-z]\s*=", q): | |
| return QuestionType.ALGEBRA | |
| if re.search(r"\d", q): | |
| return QuestionType.ARITHMETIC | |
| return QuestionType.UNKNOWN |