vader

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 13 Imported by: 1

README

VADER-Sentiment-Analysis

A powerful Go (golang) re-implementation of the VADER (Valence Aware Dictionary and sEntiment Reasoner).

Codecov Go CodeQL Go Report Card MIT

VADER is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media.

Main differences from the original implementation.

  • NO hardcoded rules, everything is configurable in the lexicon files, allowing the addition of new languages without changing the code.
  • Blazingly fast! In my machine evaluates 170.000 sentences per second vs 26.000 using the original python implementation.
  • Emojis have valence values.
  • Possibility to add exceptions to the rules.
  • Possibility to use regular expressions in the rules.
  • Possibility to normalize the input string: diacritics removal (accents removal), string replacement.

Available Languages

  • English
  • Portuguese

Benchmark

Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkPolarityScores$ github.com/knuppe/vader

goos: linux
goarch: amd64
pkg: github.com/knuppe/vader
cpu: AMD Ryzen 9 5950X 16-Core Processor            
BenchmarkPolarityScores/PolarityScores_en-32         	  176991	      7195 ns/op	    2357 B/op	      62 allocs/op
BenchmarkPolarityScores/PolarityScores_pt-32         	  144518	      7143 ns/op	    3568 B/op	      68 allocs/op
PASS
ok  	github.com/knuppe/vader	3.486s

Usage

  1. Download the desired lexicon file(s).

  2. Download the module.
    go get -u github.com/knuppe/vader@v1.0.0

  3. Have fun ;)

Here is a minimal Go program that uses this package in order to stem a single word or a sentence.

package main
import (
	"fmt"
	"github.com/knuppe/vader"
)

func main(){
	// you need to download de lexicon zip files.
	vader, err := NewVader("lexicons/en/en.zip")
	if err != nil {
		panic(err)
	}

	score := vader.PolarityScores("VADER is smart, handsome, and funny!")

	fmt.Printf(
		"neg: %.3f, neu: %.3f, pos: %.3f, compound: %.3f (%s)",
		score.Negative,
		score.Neutral,
		score.Positive,
		score.Compound,
		score.Sentiment(),
	)
	// neg: 0.000, neu: 0.248, pos: 0.752, compound: 0.844 (positive)
}

Citation

Hutto, C.J. & Gilbert, E.E. (2014). VADER: A Parsimonious Rule-based Model for Sentiment Analysis of Social Media Text. Eighth International Conference on Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.

License (MIT)

Copyright (c) 2022 Gustavo Knuppe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scores

type Scores struct {
	Negative float64
	Neutral  float64
	Positive float64
	Compound float64
}

Scores encapsulates a single sentiment measure for a statement

func (*Scores) Sentiment

func (s *Scores) Sentiment() string

Sentiment returns the score sentiment "positive" (compound score >= 0.05), "negative" (compound score <= -0.05) or "neutral".

type Vader

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

Vader computes sentiment intensity scores for sentences.

func NewVader

func NewVader(vaderZipFile string) (*Vader, error)

NewVader creates a new Vader instance using the zip lexicon file.

func (*Vader) PolarityScores

func (v *Vader) PolarityScores(sentence string) Scores

PolarityScores computes the sentiment strength based on the input text.

Jump to

Keyboard shortcuts

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