|
#!/bin/bash |
|
|
|
|
|
classify_text() { |
|
local text="$1" |
|
local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]') |
|
|
|
|
|
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) |
|
|
|
|
|
local gov_score=0 |
|
local econ_score=0 |
|
local law_score=0 |
|
local danger_score=0 |
|
|
|
|
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
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 [ "$1" ]; then |
|
classify_text "$1" |
|
fi |
|
|