about summary refs log tree commit diff stats
path: root/js/sentiment/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/sentiment/app.js')
-rw-r--r--js/sentiment/app.js110
1 files changed, 59 insertions, 51 deletions
diff --git a/js/sentiment/app.js b/js/sentiment/app.js
index 66735fd..1f66d92 100644
--- a/js/sentiment/app.js
+++ b/js/sentiment/app.js
@@ -210,45 +210,38 @@ const createWebSentimentAnalyzer = (config = {}) => {
             
             // Emotion categories for classification
             const emotionCategories = {
-                // Positive Emotions
-                joy: ['happy', 'joy', 'delighted', 'pleased', 'excited', 'ecstatic', 'elated', 'jubilant', 'thrilled', 'overjoyed'],
-                gratitude: ['grateful', 'thankful', 'blessed', 'appreciative', 'indebted', 'humbled', 'moved'],
-                satisfaction: ['content', 'satisfied', 'fulfilled', 'pleased', 'accomplished', 'proud', 'complete'],
-                optimism: ['optimistic', 'hopeful', 'promising', 'confident', 'assured', 'encouraged', 'positive'],
-                serenity: ['peaceful', 'calm', 'tranquil', 'relaxed', 'serene', 'composed', 'centered'],
-                amusement: ['fun', 'funny', 'amused', 'entertained', 'playful', 'silly', 'humorous', 'laughing'],
-                interest: ['curious', 'intrigued', 'fascinated', 'engaged', 'absorbed', 'captivated', 'inspired'],
-                admiration: ['impressed', 'awed', 'amazed', 'respected', 'valued', 'esteemed', 'revered'],
-                love: ['loving', 'adoring', 'fond', 'affectionate', 'caring', 'cherished', 'devoted'],
-                
-                // Negative Emotions
-                frustration: ['frustrated', 'annoyed', 'irritated', 'agitated', 'exasperated', 'thwarted', 'hindered'],
-                concern: ['worried', 'concerned', 'anxious', 'uneasy', 'apprehensive', 'troubled', 'disturbed'],
-                disappointment: ['disappointed', 'letdown', 'dissatisfied', 'disheartened', 'dismayed', 'unfulfilled'],
-                anger: ['angry', 'furious', 'outraged', 'enraged', 'hostile', 'irate', 'livid', 'incensed'],
-                sadness: ['sad', 'unhappy', 'sorrowful', 'depressed', 'melancholy', 'gloomy', 'heartbroken'],
-                fear: ['afraid', 'scared', 'fearful', 'terrified', 'panicked', 'petrified', 'dreading'],
-                confusion: ['confused', 'puzzled', 'perplexed', 'bewildered', 'disoriented', 'uncertain', 'unclear'],
-                regret: ['regretful', 'sorry', 'remorseful', 'guilty', 'apologetic', 'ashamed', 'contrite'],
+                // Strong positive emotions (weight: 2.0)
+                joy: {
+                    weight: 2.0,
+                    words: ['happy', 'joy', 'delighted', 'pleased', 'excited', 'ecstatic']
+                },
+                love: {
+                    weight: 2.0, 
+                    words: ['loving', 'adoring', 'fond', 'affectionate', 'caring']
+                },
                 
-                // Complex Emotions
-                anticipation: ['eager', 'anticipating', 'expecting', 'awaiting', 'looking forward', 'preparing'],
-                surprise: ['surprised', 'astonished', 'startled', 'shocked', 'stunned', 'unexpected', 'remarkable'],
-                nostalgia: ['nostalgic', 'reminiscent', 'remembering', 'longing', 'wistful', 'retrospective'],
-                determination: ['determined', 'resolved', 'committed', 'focused', 'dedicated', 'persistent', 'steadfast'],
-                relief: ['relieved', 'reassured', 'unburdened', 'comforted', 'calmed', 'settled', 'eased'],
-                ambivalence: ['conflicted', 'uncertain', 'unsure', 'mixed feelings', 'undecided', 'torn'],
+                // Moderate positive emotions (weight: 1.5)
+                satisfaction: {
+                    weight: 1.5,
+                    words: ['content', 'satisfied', 'fulfilled', 'pleased', 'accomplished']
+                },
                 
-                // Professional/Work-Related
-                confidence: ['confident', 'capable', 'competent', 'skilled', 'proficient', 'qualified', 'expert'],
-                motivation: ['motivated', 'driven', 'inspired', 'energized', 'enthusiastic', 'passionate', 'eager'],
-                productivity: ['productive', 'efficient', 'effective', 'accomplished', 'successful', 'achieving'],
-                collaboration: ['collaborative', 'cooperative', 'supportive', 'helpful', 'team-oriented', 'united'],
+                // Strong negative emotions (weight: -2.0)
+                anger: {
+                    weight: -2.0,
+                    words: ['angry', 'furious', 'outraged', 'enraged', 'hostile']
+                },
+                hate: {
+                    weight: -2.0,
+                    words: ['hate', 'despise', 'loathe', 'detest', 'abhor']
+                },
                 
-                // Growth/Learning
-                growth: ['growing', 'developing', 'improving', 'progressing', 'advancing', 'learning', 'evolving'],
-                curiosity: ['curious', 'inquisitive', 'interested', 'exploring', 'discovering', 'wondering'],
-                insight: ['understanding', 'realizing', 'comprehending', 'grasping', 'enlightened', 'aware']
+                // Moderate negative emotions (weight: -1.5)
+                frustration: {
+                    weight: -1.5,
+                    words: ['frustrated', 'annoyed', 'irritated', 'agitated']
+                }
+                // ... other categories with appropriate weights
             };
             
             for (let i = 0; i < words.length; i++) {
@@ -275,31 +268,39 @@ const createWebSentimentAnalyzer = (config = {}) => {
                 
                 // Score the word and categorize emotions
                 if (config.positiveWords.has(word)) {
-                    const wordScore = 1 * multiplier;
+                    // Increase base score for positive words
+                    const baseScore = 2;
+                    const wordScore = baseScore * multiplier;
                     score += wordScore;
                     positiveCount++;
                     wordImpact.score = wordScore;
                     
-                    // Categorize emotion
-                    for (const [category, keywords] of Object.entries(emotionCategories)) {
-                        if (keywords.includes(word)) {
+                    // Categorize emotion with weights
+                    for (const [category, {weight, words}] of Object.entries(emotionCategories)) {
+                        if (words.includes(word)) {
                             wordImpact.category = category;
                             emotionCounts.set(category, (emotionCounts.get(category) || 0) + 1);
+                            // Add weighted bonus score
+                            score += weight * multiplier;
                             break;
                         }
                     }
                     
                 } else if (config.negativeWords.has(word)) {
-                    const wordScore = -1 * multiplier;
+                    // Increase base score for negative words
+                    const baseScore = -2;
+                    const wordScore = baseScore * multiplier;
                     score += wordScore;
                     negativeCount++;
                     wordImpact.score = wordScore;
                     
-                    // Categorize emotion
-                    for (const [category, keywords] of Object.entries(emotionCategories)) {
-                        if (keywords.includes(word)) {
+                    // Categorize emotion with weights
+                    for (const [category, {weight, words}] of Object.entries(emotionCategories)) {
+                        if (words.includes(word)) {
                             wordImpact.category = category;
                             emotionCounts.set(category, (emotionCounts.get(category) || 0) + 1);
+                            // Add weighted bonus score
+                            score -= weight * multiplier;
                             break;
                         }
                     }
@@ -329,20 +330,27 @@ const createWebSentimentAnalyzer = (config = {}) => {
                 .slice(0, 3)
                 .map(([emotion, count]) => ({ emotion, count }));
             
+            // Calculate the final score and clamp it between -10 and 10
+            const clampedScore = Math.max(-10, Math.min(10, score));
+
+            // Only count words that contribute to sentiment
+            const sentimentWords = positiveCount + negativeCount;
+            const averageSentiment = sentimentWords > 0 ? clampedScore / sentimentWords : 0;
+
             return {
-                score,
+                score: clampedScore,
                 words: analyzedWords,
                 summary: {
                     positive: positiveCount,
                     negative: negativeCount,
-                    neutral: words.length - positiveCount - negativeCount,
+                    sentiment_words: sentimentWords,
                     total: words.length
                 },
-                sentiment: getEmotionalTone(score),
+                sentiment: getEmotionalTone(clampedScore),
                 topEmotions,
-                intensity: getIntensity(score, intensifierCount),
+                intensity: getIntensity(clampedScore, intensifierCount),
                 wordCount: words.length,
-                averageSentiment: score / words.length || 0
+                averageSentiment
             };
         };
 
@@ -649,7 +657,7 @@ Overall Assessment:
 Word Breakdown:
 • Positive Words: ${summary.positive}
 • Negative Words: ${summary.negative}
-• Neutral Words: ${summary.neutral}
+• Sentiment-Carrying Words: ${summary.sentiment_words} (of ${summary.total} total)
 
 ${topEmotions.length ? `Dominant Emotions:
 ${topEmotions.map(e => `• ${e.emotion} (mentioned ${e.count} time${e.count > 1 ? 's' : ''})`).join('\n')}` : ''}
@@ -735,7 +743,7 @@ const main = async () => {
     }
 
     // Create analyzer instance
-    const analyzer = createWebSentimentAnalyzer();
+    // const analyzer = createWebSentimentAnalyzer();
 
     // Analyze each URL
     for (const url of args) {
100 CI fix timeout error (#13134)' href='/ahoang/Nim/commit/azure-pipelines.yml?h=devel&id=d5f011d9e634f1de7046ecec89665048da525fbc'>d5f011d9e ^
c292c57e4 ^







d5f011d9e ^




c292c57e4 ^
d5f011d9e ^


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