SamanthaStorm commited on
Commit
3eb0e20
·
verified ·
1 Parent(s): 623fdc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -102,19 +102,31 @@ def detect_contradiction(message):
102
  return any(re.search(pat, message, flags) for pat, flags in patterns)
103
 
104
  def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
105
- hits = len([p for p in patterns if p in DARVO_PATTERNS])
106
- p_score = hits / len(DARVO_PATTERNS)
107
- s_shift = max(0.0, sentiment_after - sentiment_before)
108
- m_hits = len([m for m in motifs_found if any(f.lower() in m.lower() for f in DARVO_MOTIFS)])
109
- m_score = m_hits / len(DARVO_MOTIFS)
110
- c_score = 1.0 if contradiction_flag else 0.0
 
 
 
 
 
 
 
 
 
 
 
 
111
  raw = (
112
  0.25 * pattern_score
113
  + 0.30 * sentiment_shift_score
114
  + 0.35 * motif_score
115
  + 0.10 * contradiction_score
116
  )
117
- return round(min(raw,1.0),3)
118
 
119
  def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
120
  label = top_label.split(" – ")[0]
 
102
  return any(re.search(pat, message, flags) for pat, flags in patterns)
103
 
104
  def calculate_darvo_score(patterns, sentiment_before, sentiment_after, motifs_found, contradiction_flag=False):
105
+ # count how many DARVO patterns were triggered
106
+ pattern_hits = len([p for p in patterns if p in DARVO_PATTERNS])
107
+ pattern_score = pattern_hits / len(DARVO_PATTERNS)
108
+
109
+ # measure how much sentiment shifts toward negativity
110
+ sentiment_shift_score = max(0.0, sentiment_after - sentiment_before)
111
+
112
+ # count DARVO motif occurrences
113
+ motif_hits = len([
114
+ m for m in motifs_found
115
+ if any(phrase.lower() in m.lower() for phrase in DARVO_MOTIFS)
116
+ ])
117
+ motif_score = motif_hits / len(DARVO_MOTIFS)
118
+
119
+ # direct contradiction indicator
120
+ contradiction_score = 1.0 if contradiction_flag else 0.0
121
+
122
+ # reweighted: pattern 25%, sentiment 30%, motifs 35%, contradiction 10%
123
  raw = (
124
  0.25 * pattern_score
125
  + 0.30 * sentiment_shift_score
126
  + 0.35 * motif_score
127
  + 0.10 * contradiction_score
128
  )
129
+ return round(min(raw, 1.0), 3)
130
 
131
  def generate_risk_snippet(abuse_score, top_label, escalation_score, stage):
132
  label = top_label.split(" – ")[0]