Spaces:
Running
Running
File size: 1,028 Bytes
2ab97c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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 |