sentiment

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SentimentBoost

func SentimentBoost(queryLabel, neuronLabel Label) float64

SentimentBoost returns a score multiplier [0.8, 1.2] that can be applied to search scoring when the query and neuron share the same emotional valence. Same label → boost (1.2), opposite valence → slight penalty (0.8), else neutral (1.0).

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer wraps govader's SentimentIntensityAnalyzer and maps its output to the six basic emotions. It is safe for concurrent use.

func Default

func Default() *Analyzer

Default returns the package-level singleton Analyzer (lazy-initialized).

func New

func New() *Analyzer

New creates a new Analyzer. Prefer Default() for shared use.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(text string) Result

Analyze returns the sentiment Result for the given text. The Label is derived from VADER polarity scores using the mapping below:

compound >=  0.60  → happiness   (strong positive)
compound >=  0.20  → surprise    (mild positive — unexpected/arousing)
compound <= -0.60  → anger/disgust/fear (disambiguated by neg intensity)
compound <= -0.20  → sadness     (mild negative)
otherwise          → neutral

Within the strong-negative band, the highest sub-score among neg/pos/neu is used to pick anger vs disgust vs fear heuristically.

type Label

type Label string

Label represents one of the six universal basic emotions plus neutral. Mapping follows Ekman (1992) — the six emotions with universal facial expressions.

const (
	LabelHappiness Label = "happiness"
	LabelSadness   Label = "sadness"
	LabelFear      Label = "fear"
	LabelAnger     Label = "anger"
	LabelDisgust   Label = "disgust"
	LabelSurprise  Label = "surprise"
	LabelNeutral   Label = "neutral"
)

type Result

type Result struct {
	Label    Label   // Dominant basic emotion
	Compound float64 // VADER compound score [-1, 1]
	Positive float64 // VADER positive ratio [0, 1]
	Negative float64 // VADER negative ratio [0, 1]
	Neutral  float64 // VADER neutral ratio [0, 1]
}

Result holds the full sentiment analysis output for a piece of text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL