File size: 10,082 Bytes
25e624c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
"""
Sentiment Keyword Mapping - Direct keyword to emotion mapping

This module maintains the word→emotion mappings
It's the data layer for sentiment analysis
"""

from typing import Dict, Set, Optional


class KeywordMap:
    """Maps emotion keywords to standardized emotion labels"""
    
    EMOTION_KEYWORDS: Dict[str, str] = {
        # JOY / HAPPINESS
        "happy": "happiness",
        "happiness": "happiness",
        "joyful": "joy",
        "joy": "joy",
        "glad": "happiness",
        "pleased": "happiness",
        "delighted": "delight",
        "cheerful": "cheerfulness",
        "merry": "joy",
        "jolly": "joy",
        "elated": "elation",
        "ecstatic": "ecstasy",
        "euphoric": "euphoria",
        "thrilled": "thrill",
        "overjoyed": "joy",
        "blissful": "contentment",
        
        # EXCITEMENT / ENTHUSIASM
        "excited": "excitement",
        "exciting": "excitement",
        "enthusiastic": "enthusiasm",
        "eager": "enthusiasm",
        "pumped": "excitement",
        "hyped": "excitement",
        "stoked": "excitement",
        "psyched": "excitement",
        
        # LOVE / AFFECTION
        "love": "love",
        "loving": "love",
        "adore": "adoration",
        "cherish": "love",
        "affection": "affection",
        "fond": "affection",
        "caring": "caring",
        "tender": "tenderness",
        "warm": "affection",
        "devoted": "love",
        
        # GRATITUDE
        "grateful": "gratitude",
        "thankful": "gratitude",
        "thanks": "gratitude",
        "thank": "gratitude",
        "appreciate": "gratitude",
        "blessed": "gratitude",
        
        # CONTENTMENT / SATISFACTION
        "good": "happiness",
        "great": "happiness",
        "excellent": "happiness",
        "awesome": "happiness",
        "ok": "contentment",
        "okay": "contentment",
        "fine": "contentment",
        "well": "contentment",
        "content": "contentment",
        "satisfied": "satisfaction",
        "peaceful": "serenity",
        "serene": "serenity",
        "calm": "calm",
        "relaxed": "relaxed",
        "comfortable": "contentment",
        "cozy": "contentment",
        "pleasant": "pleasure",
        
        # INTEREST / CURIOSITY
        "curious": "curiosity",
        "interested": "interest",
        "intrigued": "intrigue",
        "fascinated": "fascination",
        "captivated": "fascination",
        "wondering": "curiosity",
        "wonder": "wonder",
        
        # SURPRISE / AWE
        "surprised": "surprise",
        "surprising": "surprise",
        "amazed": "amazement",
        "amazing": "amazement",
        "astonished": "astonishment",
        "shocked": "shock",
        "stunned": "shock",
        "wow": "amazement",
        "incredible": "amazement",
        "unbelievable": "astonishment",
        "awesome": "awe",
        "awe": "awe",
        
        # SADNESS
        "sad": "sadness",
        "unhappy": "sadness",
        "depressed": "despair",
        "miserable": "misery",
        "sorrowful": "sorrow",
        "grief": "grief",
        "grieving": "grief",
        "heartbroken": "grief",
        "devastated": "despair",
        "gloomy": "melancholy",
        "melancholy": "melancholy",
        "down": "sadness",
        "tearful": "sadness",
        "crying": "sorrow",
        
        # LONELINESS
        "lonely": "loneliness",
        "alone": "loneliness",
        "isolated": "loneliness",
        "abandoned": "loneliness",
        "forsaken": "loneliness",
        
        # DISAPPOINTMENT
        "disappointed": "disappointment",
        "letdown": "disappointment",
        "dismayed": "disappointment",
        "disheartened": "disappointment",
        
        # FEAR / ANXIETY
        "afraid": "fear",
        "scared": "fear",
        "frightened": "fear",
        "terrified": "terror",
        "horrified": "horror",
        "fearful": "fear",
        "anxious": "anxiety",
        "nervous": "nervousness",
        "worried": "worry",
        "worrying": "worry",
        "uneasy": "anxiety",
        "tense": "nervousness",
        "stressed": "anxiety",
        "panicked": "panic",
        "panicking": "panic",
        "dread": "dread",
        "dreading": "dread",
        "apprehensive": "apprehension",
        
        # ANGER
        "angry": "anger",
        "mad": "anger",
        "furious": "fury",
        "enraged": "rage",
        "outraged": "rage",
        "livid": "fury",
        "irate": "anger",
        "irritated": "irritation",
        "annoyed": "annoyance",
        "frustrated": "frustration",
        "frustrating": "frustration",
        "aggravated": "irritation",
        "infuriated": "fury",
        "pissed": "anger",
        "resentful": "resentment",
        "bitter": "bitterness",
        "hostile": "hostility",
        "hate": "anger",
        "hating": "anger",
        "terrible": "anger",
        "horrible": "disgust",
        "awful": "disgust",
        
        # DISGUST
        "disgusted": "disgust",
        "disgusting": "disgust",
        "gross": "disgust",
        "revolting": "revulsion",
        "repulsed": "revulsion",
        "sickened": "disgust",
        "nauseated": "disgust",
        "appalled": "disgust",
        
        # CONTEMPT
        "contempt": "contempt",
        "disdain": "disdain",
        "scorn": "scorn",
        "dismissive": "contempt",
        "condescending": "contempt",
        
        # SHAME / EMBARRASSMENT
        "ashamed": "shame",
        "shameful": "shame",
        "embarrassed": "embarrassment",
        "embarrassing": "embarrassment",
        "humiliated": "humiliation",
        "mortified": "humiliation",
        "guilty": "guilt",
        "regret": "regret",
        "remorseful": "remorse",
        "sorry": "regret",
        
        # CONFUSION
        "confused": "confused",
        "confusing": "confused",
        "puzzled": "puzzled",
        "perplexed": "perplexed",
        "bewildered": "bewildered",
        "baffled": "baffled",
        "lost": "confused",
        "uncertain": "uncertain",
        
        # BOREDOM
        "bored": "boredom",
        "boring": "boredom",
        "dull": "boredom",
        "uninterested": "boredom",
        "tedious": "boredom",
        
        # TIREDNESS
        "tired": "tiredness",
        "exhausted": "exhaustion",
        "weary": "weariness",
        "fatigued": "fatigue",
        "sleepy": "sleepy",
        "drowsy": "sleepy",
        "drained": "exhaustion",
        
        # ENVY / JEALOUSY
        "jealous": "jealousy",
        "envious": "envy",
        "covetous": "envy",
        
        # NOSTALGIA
        "nostalgic": "nostalgia",
        "reminiscing": "nostalgia",
        "miss": "longing",
        "missing": "longing",
        "longing": "longing",
        "yearning": "yearning",
        
        # PLAYFUL / AMUSEMENT
        "playful": "playful",
        "silly": "silly",
        "goofy": "silly",
        "mischievous": "mischievous",
        "teasing": "teasing",
        "joking": "playful",
        "funny": "amusement",
        "hilarious": "amusement",
        "lol": "amusement",
        "haha": "amusement",
        "hehe": "amusement",
        "lmao": "amusement",
        "rofl": "amusement",
        
        # EMPATHY / SYMPATHY
        "sympathetic": "sympathy",
        "empathetic": "empathy",
        "compassionate": "compassion",
        "understanding": "empathy",
        "supportive": "caring",
    }
    
    # Intensifiers that strengthen emotion
    INTENSIFIERS: Set[str] = {
        "very", "really", "extremely", "so", "incredibly", "absolutely",
        "totally", "completely", "utterly", "deeply", "truly", "highly",
        "super", "mega", "ultra", "insanely", "ridiculously"
    }
    
    # Negations that flip emotion
    NEGATIONS: Set[str] = {
        "not", "no", "never", "dont", "doesnt", "didnt", "wont",
        "cant", "cannot", "couldnt", "wouldnt", "shouldnt", "isnt",
        "arent", "wasnt", "werent", "hardly", "barely", "neither"
    }
    
    # Emotion opposites for negation handling
    EMOTION_OPPOSITES: Dict[str, str] = {
        "happiness": "sadness",
        "joy": "sadness",
        "love": "neutral",
        "hope": "despair",
        "excitement": "boredom",
        "calm": "anxiety",
        "confidence": "fear",
        "satisfaction": "disappointment",
        "sadness": "happiness",
        "anger": "calm",
        "fear": "confidence",
        "boredom": "excitement",
        "despair": "hope",
        "anxiety": "calm",
    }
    
    def __init__(self, custom_keywords: Optional[Dict[str, str]] = None):
        """Initialize with default or custom keywords"""
        self.keywords = self.EMOTION_KEYWORDS.copy()
        if custom_keywords:
            self.keywords.update(custom_keywords)
    
    def get_emotion_for_word(self, word: str) -> Optional[str]:
        """Get emotion for a single word"""
        word_clean = word.lower().strip()
        return self.keywords.get(word_clean)
    
    def is_intensifier(self, word: str) -> bool:
        """Check if word is an intensifier"""
        return word.lower() in self.INTENSIFIERS
    
    def is_negation(self, word: str) -> bool:
        """Check if word is a negation"""
        return word.lower() in self.NEGATIONS
    
    def get_opposite_emotion(self, emotion: str) -> str:
        """Get opposite emotion (for negation handling)"""
        return self.EMOTION_OPPOSITES.get(emotion, "neutral")
    
    def get_all_emotions(self) -> Dict[str, str]:
        """Get all emotion keywords"""
        return self.keywords.copy()


if __name__ == "__main__":
    kmap = KeywordMap()
    print(f"Loaded {len(kmap.keywords)} keywords")
    print(f"Sample: 'happy' -> {kmap.get_emotion_for_word('happy')}")
    print(f"Sample: 'sad' -> {kmap.get_emotion_for_word('sad')}")
    print(f"Is 'very' intensifier? {kmap.is_intensifier('very')}")
    print(f"Is 'not' negation? {kmap.is_negation('not')}")