CoolFace
Apppublic

kasinathansj/Categorization_2

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
severity_check.py42 linesDownload Raw Back to root
1# severity_keywords.py
2
3# Map each keyword to its severity level
4SEVERITY_LOOKUP = {}
5
6SEVERITY_KEYWORDS = {
7    "High": [
8        "immediately", "urgent", "critical", "as soon as possible", "emergency", 
9        "high priority", "top priority", "act now", "requires immediate attention", 
10        "important", "severe", "time-sensitive"
11    ],
12    "Medium": [
13        "ASAP", "soon", "moderate", "needs attention", "fairly important",
14        "whenever possible", "within a reasonable time", "should be addressed"
15    ],
16    "Low": [
17        "minor", "low priority", "not urgent", "whenever convenient", "can wait",
18        "optional", "not immediate", "no rush", "take your time"
19    ]
20}
21
22# Assign severity levels numerically for comparison
23SEVERITY_ORDER = {"High": 3, "Medium": 2, "Low": 1, "Unknown": 0}
24
25# Populate HashMap for fast lookups
26for severity, keywords in SEVERITY_KEYWORDS.items():
27    for keyword in keywords:
28        SEVERITY_LOOKUP[keyword] = severity  # { "urgent": "High", "ASAP": "Medium", ... }
29
30
31def get_highest_severity_word(text):
32    """Find the highest severity word dynamically using max() for efficiency."""
33    words = text.lower().split()
34    
35    highest_word, highest_severity = max(
36        ((word, SEVERITY_LOOKUP[word]) for word in words if word in SEVERITY_LOOKUP),
37        key=lambda item: SEVERITY_ORDER[item[1]],
38        default=(None, None)
39    )
40
41    return highest_severity
42