diff options
author | elioat <{ID}+{username}@users.noreply.github.com> | 2025-02-24 08:19:11 -0500 |
---|---|---|
committer | elioat <{ID}+{username}@users.noreply.github.com> | 2025-02-24 08:19:11 -0500 |
commit | bece034f01c069b0f25fb244768bb23215d0115c (patch) | |
tree | 1d98a62208ea84f089aa4eda338f62b164a34f75 | |
parent | 804242ba74e3fa0cfb6a6d164132d477fa04705b (diff) | |
download | tour-bece034f01c069b0f25fb244768bb23215d0115c.tar.gz |
*
-rw-r--r-- | js/sentiment/app.js | 110 | ||||
-rwxr-xr-x | js/sentiment/bun.lockb | bin | 25383 -> 25383 bytes |
2 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) { diff --git a/js/sentiment/bun.lockb b/js/sentiment/bun.lockb index e7e3ab3..00cbdac 100755 --- a/js/sentiment/bun.lockb +++ b/js/sentiment/bun.lockb Binary files differ |