# motif_tagging.py import re MOTIF_PATTERNS = { "threat": [ r"\b(i['’]m|i am) going to (hurt|kill|break|ruin|destroy|end|bash|beat|smash|wreck) you\b", r"\b(i['’]?ll|i will) (hurt|kill|ruin|wreck|end|destroy|obliterate|crush|eliminate|beat) you\b", r"\b(i['’]?ll|i will) make you disappear\b", r"\b(i['’]?ll|i will) put you in (a|the) (grave|hospital|ground|dirt|bodybag)\b", r"\b(i['’]?ll|i will) snap your (neck|spine|arm|leg)\b", r"\b(i['’]?ll|i will) break your (face|jaw|legs|arms|neck)\b", r"\b(i['’]?ll|i will) beat the (shit|hell|crap) out of you\b", r"\b(i['’]?ll|i will) f\*?ck you up\b", r"\b(i['’]?ll|i will) (come for|find|hunt|get) you\b", r"\b(i['’]?ll|i will) put you down\b", r"\b(i['’]?ll|i will) end you\b", r"\bi hope you (die|suffer|disappear)\b", r"\byou better (run|hide|watch your back)\b", r"\bsay goodbye\b.*\byou\b", r"\bsleep with one eye open\b", r"\b(i['’]?ll|i will) send you to (hell|the morgue)\b", r"\b(i['’]?ll|i will) make sure you’re never seen again\b", r"\b(i['’]?ll|i will|ill) put you in (a|the) rose garden\b" r"\b(i (won[’']?t|will not) let you (leave|go|talk to|see|text|spend time with) (him|her|them|anyone))\b", r"\b(you (can[’']?t|are not allowed to|shouldn’t)) (go out|leave|talk to|see|text|spend time with|have friends)\b", r"\b(i (decide|get to decide|control|own) what you (do|say|wear|eat|spend|see|talk to))\b", r"\b(you['’]?re|you are) not allowed to (leave|talk to anyone|have your phone)\b", r"\bi make the rules\b", r"\bit’s my way or nothing\b", r"\bi’ll take your (car|keys|money|phone)\b", r"\byou don’t need anyone else\b", r"\byou belong to me\b", r"\bwithout me, you’re (nothing|no one)\b", r"\byou do what i say\b", r"\b(you better|you have to) do what i say\b", r"\b(you['’]?re not going|you’re not leaving|i won’t let you go)\b" r"\b(i['’]?ll|i will) (kill|hurt) myself (if you leave|if you don’t come back|unless you stay)\b", r"\bi (don’t|do not) want to live (without you|if you leave)\b", r"\bi['’]?ll (die|disappear|end it) (if|unless) you (leave|go|don’t call)\b", r"\b(if )?i['’]?ll make you watch me (suffer|bleed)\b", r"\bi['’]?ll do something bad (to myself|if you leave)\b", r"\bi['’]?ll regret it when i’m gone\b", r"\bi can’t live without you\b", r"\bmaybe (i should just die|it’d be better if i were dead)\b", r"\bi’m better off dead\b", r"\bi['’]?ll disappear forever if you walk out\b" ] } def detect_motifs(text): tags = [] matched_phrases = [] text_lower = text.lower() for label, patterns in MOTIF_PATTERNS.items(): for pattern in patterns: match = re.search(pattern, text_lower) if match: tags.append(label) matched_phrases.append((label, match.group())) break return tags, matched_phrases