SamanthaStorm commited on
Commit
7f3126b
·
verified ·
1 Parent(s): 7a79da7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
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
- pattern_hits = sum(1 for p in patterns if p in DARVO_PATTERNS or any(d in p.lower() for d in ["blame", "project", "dismiss", "guilt", "contradict"]))
142
- pattern_score = pattern_hits / len(DARVO_PATTERNS)
143
 
144
- # 🎯 New: If 2+ DARVO patterns are hit, ignore sentiment discount
145
- if pattern_hits >= 2:
146
- sentiment_shift_score = 0.2
147
- else:
148
- sentiment_shift_score = max(0.0, sentiment_after - sentiment_before)
149
 
150
- text_lower = " ".join(motifs_found).lower()
151
- motif_hits = len([
152
- phrase for phrase in DARVO_MOTIFS
153
- if phrase.lower() in text_lower
154
- ])
155
- motif_score = motif_hits / len(DARVO_MOTIFS)
 
156
 
 
157
  contradiction_score = 1.0 if contradiction_flag else 0.0
158
 
 
159
  return round(min(
160
- 0.3 * pattern_score +
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