Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,143 Bytes
87d95ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# motif_tagging.py
import re
MOTIF_PATTERNS = {
"physical_threat": [
r"\b(i'?ll|i am going to) (hurt|kill|break|end|ruin|destroy) you\b",
r"\bsay goodbye to (your|those)? (kneecaps|teeth|face)\b",
r"\bi'?ll put you in a (grave|hole|rose garden)\b",
r"\b(sleep with one eye open|you’ll see what happens)\b",
r"\bi'?ll make you disappear\b",
],
"extreme_control": [
r"\bi decide who you (see|talk to|text|spend time with)\b",
r"\byou’re not allowed to\b",
r"\byou don’t get to (leave|say no|argue)\b",
r"\bi own you\b",
],
"suicidal_threat": [
r"\bi'?ll kill myself\b",
r"\bi don’t want to live if you leave\b",
r"\bi’ll die without you\b",
r"\byou’ll regret it when i’m gone\b",
],
}
def tag_motifs(text):
tags = set()
matches = []
for label, patterns in MOTIF_PATTERNS.items():
for pattern in patterns:
if re.search(pattern, text, flags=re.IGNORECASE):
tags.add(label)
matches.append((label, pattern))
return list(tags), matches |