Tether / motif_tagging.py
SamanthaStorm's picture
Create motif_tagging.py
87d95ff verified
raw
history blame
1.14 kB
# 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