Create question_classifier.py
Browse files- question_classifier.py +66 -0
question_classifier.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def classify_question(question_text: str, category: str) -> dict:
|
| 5 |
+
q = question_text.lower()
|
| 6 |
+
|
| 7 |
+
if category == "Quantitative":
|
| 8 |
+
|
| 9 |
+
if "percent" in q or "%" in q:
|
| 10 |
+
if "then" in q:
|
| 11 |
+
return {"topic": "percent", "type": "successive_percent"}
|
| 12 |
+
return {"topic": "percent", "type": "percent_change"}
|
| 13 |
+
|
| 14 |
+
if "ratio" in q:
|
| 15 |
+
return {"topic": "ratio", "type": "ratio_total"}
|
| 16 |
+
|
| 17 |
+
if "probability" in q or "chosen at random" in q:
|
| 18 |
+
return {"topic": "probability", "type": "simple_probability"}
|
| 19 |
+
|
| 20 |
+
if "divisible" in q or "remainder" in q:
|
| 21 |
+
return {"topic": "number_theory", "type": "divisibility"}
|
| 22 |
+
|
| 23 |
+
if "|" in q:
|
| 24 |
+
return {"topic": "algebra", "type": "absolute_value"}
|
| 25 |
+
|
| 26 |
+
if "circle" in q or "radius" in q or "circumference" in q:
|
| 27 |
+
return {"topic": "geometry", "type": "circle_geometry"}
|
| 28 |
+
|
| 29 |
+
if "average" in q or "mean" in q:
|
| 30 |
+
return {"topic": "statistics", "type": "average"}
|
| 31 |
+
|
| 32 |
+
if "sequence" in q:
|
| 33 |
+
return {"topic": "sequence", "type": "geometric_sequence"}
|
| 34 |
+
|
| 35 |
+
if "=" in q:
|
| 36 |
+
return {"topic": "algebra", "type": "equation"}
|
| 37 |
+
|
| 38 |
+
return {"topic": "quant", "type": "general"}
|
| 39 |
+
|
| 40 |
+
if category == "DataInsight":
|
| 41 |
+
|
| 42 |
+
if "percent" in q:
|
| 43 |
+
return {"topic": "percent", "type": "percent_change"}
|
| 44 |
+
|
| 45 |
+
if "mean" in q or "median" in q:
|
| 46 |
+
return {"topic": "statistics", "type": "distribution"}
|
| 47 |
+
|
| 48 |
+
if "correlation" in q or "scatter" in q:
|
| 49 |
+
return {"topic": "statistics", "type": "correlation"}
|
| 50 |
+
|
| 51 |
+
return {"topic": "data", "type": "general"}
|
| 52 |
+
|
| 53 |
+
if category == "Verbal":
|
| 54 |
+
|
| 55 |
+
if "meaning" in q:
|
| 56 |
+
return {"topic": "vocabulary", "type": "definition"}
|
| 57 |
+
|
| 58 |
+
if "grammatically" in q:
|
| 59 |
+
return {"topic": "grammar", "type": "sentence_correction"}
|
| 60 |
+
|
| 61 |
+
if "argument" in q or "author" in q:
|
| 62 |
+
return {"topic": "reasoning", "type": "argument_analysis"}
|
| 63 |
+
|
| 64 |
+
return {"topic": "verbal", "type": "general"}
|
| 65 |
+
|
| 66 |
+
return {"topic": "unknown", "type": "unknown"}
|