Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,30 @@ DARVO_MOTIFS = [
|
|
64 |
"so now it’s all my fault", "i’m the villain", "i’m always wrong", "you never listen",
|
65 |
"you’re attacking me", "i’m done trying", "i’m the only one who cares"
|
66 |
]
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
|
69 |
pattern_hits = len([p.lower() for p in patterns if p.lower() in DARVO_PATTERNS])
|
70 |
pattern_score = pattern_hits / len(DARVO_PATTERNS)
|
@@ -76,12 +99,7 @@ def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_fo
|
|
76 |
|
77 |
contradiction_score = 1.0 if contradiction_flag else 0.0
|
78 |
|
79 |
-
darvo_score = (
|
80 |
-
0.3 * pattern_score +
|
81 |
-
0.3 * sentiment_shift_score +
|
82 |
-
0.2 * motif_score +
|
83 |
-
0.2 * contradiction_score
|
84 |
-
)
|
85 |
return round(min(darvo_score, 1.0), 3)
|
86 |
|
87 |
def custom_sentiment(text):
|
|
|
64 |
"so now it’s all my fault", "i’m the villain", "i’m always wrong", "you never listen",
|
65 |
"you’re attacking me", "i’m done trying", "i’m the only one who cares"
|
66 |
]
|
67 |
+
import re
|
68 |
+
|
69 |
+
def detect_contradiction(message):
|
70 |
+
contradiction_flag = False
|
71 |
+
contradiction_phrases = [
|
72 |
+
# Emotional flip-flops
|
73 |
+
(r"\b(i love you).{0,15}(i hate you|you ruin everything)", re.IGNORECASE),
|
74 |
+
(r"\b(i’m sorry).{0,15}(but you|if you hadn’t)", re.IGNORECASE),
|
75 |
+
(r"\b(i’m trying).{0,15}(you never|why do you)", re.IGNORECASE),
|
76 |
+
# Control + helplessness
|
77 |
+
(r"\b(do what you want).{0,15}(you’ll regret it|i always give everything)", re.IGNORECASE),
|
78 |
+
(r"\b(i don’t care).{0,15}(you never think of me)", re.IGNORECASE),
|
79 |
+
# Passive aggression or self-victimization switch
|
80 |
+
(r"\b(i guess i’m just).{0,15}(the bad guy|worthless|never enough)", re.IGNORECASE),
|
81 |
+
]
|
82 |
+
|
83 |
+
for pattern, flags in contradiction_phrases:
|
84 |
+
if re.search(pattern, message, flags):
|
85 |
+
contradiction_flag = True
|
86 |
+
break
|
87 |
+
|
88 |
+
return contradiction_flag
|
89 |
+
contradiction_flag = detect_contradiction(text)
|
90 |
+
|
91 |
def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
|
92 |
pattern_hits = len([p.lower() for p in patterns if p.lower() in DARVO_PATTERNS])
|
93 |
pattern_score = pattern_hits / len(DARVO_PATTERNS)
|
|
|
99 |
|
100 |
contradiction_score = 1.0 if contradiction_flag else 0.0
|
101 |
|
102 |
+
darvo_score = calculate_darvo_score(pattern_labels_used, 0.0, sentiment_score, motif_phrases, contradiction_flag=contradiction_flag)
|
|
|
|
|
|
|
|
|
|
|
103 |
return round(min(darvo_score, 1.0), 3)
|
104 |
|
105 |
def custom_sentiment(text):
|