File size: 1,363 Bytes
87d95ff
 
 
 
 
 
f37af67
 
 
 
 
480cc54
f37af67
87d95ff
f37af67
 
 
87d95ff
f37af67
 
87d95ff
f37af67
 
 
 
 
87d95ff
 
 
a269921
 
3bfed49
a269921
3bfed49
87d95ff
 
480cc54
 
a269921
480cc54
a269921
3bfed49
 
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
38
39
40
41
42
43
# 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",
        r"\b(i'll|i will|ill) put you in (a|the) rose garden\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 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