Spaces:
Running
on
Zero
Running
on
Zero
# motif_tagging.py | |
import re | |
MOTIF_PATTERNS = { | |
"physical_threat": [ | |
r"\b(i am going to|i'll) (hurt|kill|break|end|ruin|destroy) you\b", | |
r"\bsay goodbye to (you|those)? (kneecaps|teeth|face)\b", | |
r"\b(i'll|i will) put you in a (grave|hole|rose garden)\b", | |
r"\bsleep with one eye open( you'll see what happens)?\b", | |
r"\b(i'll|i will) make you disappear\b", | |
], | |
"extreme_control": [ | |
r"\b(i decide|i control) who you (see|talk to|text|spend time with)\b", | |
r"\b(you('re| are) not allowed to)\b", | |
r"\byou (don't|do not) get to (leave|say no|argue)\b", | |
r"\bi own you\b", | |
], | |
"suicidal_threat": [ | |
r"\b(i'll|i will) kill myself\b", | |
r"\bi (don’t|do not) want to live if you leave\b", | |
r"\b(i’ll|i will) die without you\b", | |
r"\byou(’ll|'ll) regret it when i(’m|'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 |