File size: 2,351 Bytes
2ea9ba2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Simple text classifier

classify_text() {
    local text="$1"
    local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]')
    
    # Load keywords
    local gov_keywords=$(grep "^GOVERNMENT:" /Users/rmtariq/Documents/enhanced_priority_system/models/classification_rules.txt | cut -d: -f2)
    local econ_keywords=$(grep "^ECONOMIC:" /Users/rmtariq/Documents/enhanced_priority_system/models/classification_rules.txt | cut -d: -f2)
    local law_keywords=$(grep "^LAW:" /Users/rmtariq/Documents/enhanced_priority_system/models/classification_rules.txt | cut -d: -f2)
    local danger_keywords=$(grep "^DANGER:" /Users/rmtariq/Documents/enhanced_priority_system/models/classification_rules.txt | cut -d: -f2)
    
    # Count matches
    local gov_score=0
    local econ_score=0
    local law_score=0
    local danger_score=0
    
    # Government score
    IFS=',' read -ra KEYWORDS <<< "$gov_keywords"
    for keyword in "${KEYWORDS[@]}"; do
        if echo "$text_lower" | grep -q "$keyword"; then
            gov_score=$((gov_score + 1))
        fi
    done
    
    # Economic score
    IFS=',' read -ra KEYWORDS <<< "$econ_keywords"
    for keyword in "${KEYWORDS[@]}"; do
        if echo "$text_lower" | grep -q "$keyword"; then
            econ_score=$((econ_score + 1))
        fi
    done
    
    # Law score
    IFS=',' read -ra KEYWORDS <<< "$law_keywords"
    for keyword in "${KEYWORDS[@]}"; do
        if echo "$text_lower" | grep -q "$keyword"; then
            law_score=$((law_score + 1))
        fi
    done
    
    # Danger score
    IFS=',' read -ra KEYWORDS <<< "$danger_keywords"
    for keyword in "${KEYWORDS[@]}"; do
        if echo "$text_lower" | grep -q "$keyword"; then
            danger_score=$((danger_score + 1))
        fi
    done
    
    # Determine category with highest score
    local max_score=$gov_score
    local prediction="Government"
    
    if [ "$econ_score" -gt "$max_score" ]; then
        max_score=$econ_score
        prediction="Economic"
    fi
    
    if [ "$law_score" -gt "$max_score" ]; then
        max_score=$law_score
        prediction="Law"
    fi
    
    if [ "$danger_score" -gt "$max_score" ]; then
        max_score=$danger_score
        prediction="Danger"
    fi
    
    echo "$prediction"
}

# If called directly
if [ "$1" ]; then
    classify_text "$1"
fi