Spaces:
Sleeping
Sleeping
Update mca_comment_analyzer.py
Browse files- mca_comment_analyzer.py +8 -3
mca_comment_analyzer.py
CHANGED
|
@@ -48,20 +48,25 @@ class MCACommentAnalyzer:
|
|
| 48 |
|
| 49 |
def map_sentiment(self, pred, text):
|
| 50 |
text_lower = text.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
violation_keywords = ["violation", "violates", "illegal", "non-compliant"]
|
| 52 |
suggestion_keywords = ["should", "recommend", "suggest", "advise", "better if"]
|
| 53 |
positive_keywords = ["clear", "helpful", "good", "appreciate", "support"]
|
| 54 |
-
negative_keywords = ["confusing", "unclear", "bad", "problem"]
|
| 55 |
|
|
|
|
|
|
|
| 56 |
if any(w in text_lower for w in violation_keywords):
|
| 57 |
return "Violation"
|
| 58 |
if any(w in text_lower for w in suggestion_keywords):
|
| 59 |
return "Suggestion"
|
| 60 |
if any(w in text_lower for w in positive_keywords):
|
| 61 |
return "Positive"
|
| 62 |
-
if any(w in text_lower for w in negative_keywords):
|
| 63 |
-
return "Negative"
|
| 64 |
|
|
|
|
| 65 |
label = pred['label'].upper()
|
| 66 |
if label == "POSITIVE":
|
| 67 |
return "Positive"
|
|
|
|
| 48 |
|
| 49 |
def map_sentiment(self, pred, text):
|
| 50 |
text_lower = text.lower()
|
| 51 |
+
|
| 52 |
+
# -----------------------------
|
| 53 |
+
# Strict priority: Negative → Violation → Suggestion → Positive
|
| 54 |
+
# -----------------------------
|
| 55 |
+
negative_keywords = ["confusing", "unclear", "bad", "problem"]
|
| 56 |
violation_keywords = ["violation", "violates", "illegal", "non-compliant"]
|
| 57 |
suggestion_keywords = ["should", "recommend", "suggest", "advise", "better if"]
|
| 58 |
positive_keywords = ["clear", "helpful", "good", "appreciate", "support"]
|
|
|
|
| 59 |
|
| 60 |
+
if any(w in text_lower for w in negative_keywords):
|
| 61 |
+
return "Negative"
|
| 62 |
if any(w in text_lower for w in violation_keywords):
|
| 63 |
return "Violation"
|
| 64 |
if any(w in text_lower for w in suggestion_keywords):
|
| 65 |
return "Suggestion"
|
| 66 |
if any(w in text_lower for w in positive_keywords):
|
| 67 |
return "Positive"
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
# fallback to sentiment model
|
| 70 |
label = pred['label'].upper()
|
| 71 |
if label == "POSITIVE":
|
| 72 |
return "Positive"
|