Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -138,26 +138,26 @@ def detect_contradiction(message):
|
|
138 |
return any(re.search(p, message, flags) for p, flags in patterns)
|
139 |
|
140 |
def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
|
141 |
-
|
142 |
-
|
143 |
|
144 |
-
#
|
145 |
-
|
146 |
-
sentiment_shift_score = 0.2
|
147 |
-
else:
|
148 |
-
sentiment_shift_score = max(0.0, sentiment_after - sentiment_before)
|
149 |
|
150 |
-
|
151 |
-
motif_hits =
|
152 |
-
phrase
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
156 |
|
|
|
157 |
contradiction_score = 1.0 if contradiction_flag else 0.0
|
158 |
|
|
|
159 |
return round(min(
|
160 |
-
0.3 *
|
161 |
0.3 * sentiment_shift_score +
|
162 |
0.25 * motif_score +
|
163 |
0.15 * contradiction_score, 1.0
|
|
|
138 |
return any(re.search(p, message, flags) for p, flags in patterns)
|
139 |
|
140 |
def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
|
141 |
+
# Count all detected DARVO-related patterns
|
142 |
+
pattern_hits = sum(1 for p in patterns if p.lower() in DARVO_PATTERNS)
|
143 |
|
144 |
+
# Sentiment delta
|
145 |
+
sentiment_shift_score = max(0.0, sentiment_after - sentiment_before)
|
|
|
|
|
|
|
146 |
|
147 |
+
# Match against DARVO motifs more loosely
|
148 |
+
motif_hits = sum(
|
149 |
+
any(phrase.lower() in motif.lower() or motif.lower() in phrase.lower()
|
150 |
+
for phrase in DARVO_MOTIFS)
|
151 |
+
for motif in motifs_found
|
152 |
+
)
|
153 |
+
motif_score = motif_hits / max(len(DARVO_MOTIFS), 1)
|
154 |
|
155 |
+
# Contradiction still binary
|
156 |
contradiction_score = 1.0 if contradiction_flag else 0.0
|
157 |
|
158 |
+
# Final DARVO score
|
159 |
return round(min(
|
160 |
+
0.3 * pattern_hits +
|
161 |
0.3 * sentiment_shift_score +
|
162 |
0.25 * motif_score +
|
163 |
0.15 * contradiction_score, 1.0
|