Update conversation_logic.py
Browse files- conversation_logic.py +14 -2
conversation_logic.py
CHANGED
|
@@ -74,12 +74,24 @@ def _normalize_classified_topic(topic: Optional[str], category: Optional[str], q
|
|
| 74 |
q = (question_text or "").lower()
|
| 75 |
c = normalize_category(category)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
if t not in {"general_quant", "general", "unknown", ""}:
|
| 78 |
return t
|
| 79 |
|
| 80 |
if "%" in q or "percent" in q:
|
| 81 |
return "percent"
|
| 82 |
-
if "ratio" in q or
|
| 83 |
return "ratio"
|
| 84 |
if "probability" in q or "chosen at random" in q:
|
| 85 |
return "probability"
|
|
@@ -89,7 +101,7 @@ def _normalize_classified_topic(topic: Optional[str], category: Optional[str], q
|
|
| 89 |
return "geometry"
|
| 90 |
if any(k in q for k in ["mean", "median", "average", "sales", "revenue"]):
|
| 91 |
return "statistics" if c == "Quantitative" else "data"
|
| 92 |
-
if
|
| 93 |
return "algebra"
|
| 94 |
|
| 95 |
if c == "DataInsight":
|
|
|
|
| 74 |
q = (question_text or "").lower()
|
| 75 |
c = normalize_category(category)
|
| 76 |
|
| 77 |
+
has_ratio_form = bool(re.search(r"\b\d+\s*:\s*\d+\b", q))
|
| 78 |
+
has_algebra_form = (
|
| 79 |
+
"=" in q
|
| 80 |
+
or bool(re.search(r"\b[xyz]\b", q))
|
| 81 |
+
or bool(re.search(r"\d+[a-z]\b", q))
|
| 82 |
+
or bool(re.search(r"\b[a-z]\s*[\+\-\*/=]", q))
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# override suspicious ratio classifications caused by prompt punctuation like "Solve:"
|
| 86 |
+
if t == "ratio" and not has_ratio_form and has_algebra_form:
|
| 87 |
+
t = "algebra"
|
| 88 |
+
|
| 89 |
if t not in {"general_quant", "general", "unknown", ""}:
|
| 90 |
return t
|
| 91 |
|
| 92 |
if "%" in q or "percent" in q:
|
| 93 |
return "percent"
|
| 94 |
+
if "ratio" in q or has_ratio_form:
|
| 95 |
return "ratio"
|
| 96 |
if "probability" in q or "chosen at random" in q:
|
| 97 |
return "probability"
|
|
|
|
| 101 |
return "geometry"
|
| 102 |
if any(k in q for k in ["mean", "median", "average", "sales", "revenue"]):
|
| 103 |
return "statistics" if c == "Quantitative" else "data"
|
| 104 |
+
if has_algebra_form or "what is x" in q or "what is y" in q or "integer" in q:
|
| 105 |
return "algebra"
|
| 106 |
|
| 107 |
if c == "DataInsight":
|