AFINN-based sentiment analysis for dart

Overview

Dart Sentiment

Flutter Community: dart_sentiment

pub package

AFINN-based sentiment analysis for dart

Dart Sentiment is a dart package that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text. Dart Sentiment provides several things:

  • Provide Language support for English, Italian, French and German.
  • Provide support for various emojis.
  • Based on analysis of text, provide an integer value in the range -n to +n (see details below)

Installation

add following dependency to your pubspec.yaml

dependencies:  
	dart_sentiment: 
   
	

Example

import 'package:dart_sentiment/dart_sentiment.dart';  
  
void main() {  
  final sentiment = Sentiment();  
  
  print(sentiment.analysis("The cake she made was terrible 😐"));  
  
  print(sentiment.analysis("The cake she made was terrible 😐", emoji: true));  
  
  print(sentiment.analysis("I love cats, but I am allergic to them.",));  
  
  print(sentiment.analysis("J'adore les chats, mais j'y suis allergique.",  
  languageCode: LanguageCode.french));  
  
  print(sentiment.analysis("Le gâteau qu'elle a fait était horrible 😐",  
  emoji: true, languageCode: LanguageCode.french));  
}

Function defination

Param Description
String text Input phrase to analyze
bool emoji = false Input emoji is present in the phrase to analyze
LanguageCode languageCode = LanguageCode.english Language to use for sentiment analysis. LanguageCode { english, italian, french, german }

How it works

AFINN

AFINN is a list of words rated for valence with an integer between minus five (negative) and plus five (positive). Sentiment analysis is performed by cross-checking the string tokens (words, emojis) with the AFINN list and getting their respective scores. The comparative score is simply: sum of each token / number of tokens. So for example let's take the following:

I love cats, but I am allergic to them.

That string results in the following:

{
	score: 1,  
	comparative: 0.1111111111111111,  
	tokens: [  
		"i",  
		"love",  
		"cats",  
		"but",  
		"i",  
		"am",  
		"allergic",  
		"to",  
		"them"  
	],  
	positive: [[love, 3]],  
	negative: [[allergic, 2]]  
}  
  • Returned Objects
    • Score: Score calculated by adding the sentiment values of recognized words.
    • Comparative: Comparative score of the input string.
    • Token: All the tokens like words or emojis found in the input string.
    • Words: List of words from input string that were found in AFINN list.
    • Positive: List of positive words in input string that were found in AFINN list.
    • Negative: List of negative words in input string that were found in AFINN list.

In this case, love has a value of 3, allergic has a value of -2, and the remaining tokens are neutral with a value of 0. Because the string has 9 tokens the resulting comparative score looks like: (3 + -2) / 9 = 0.111111111

This approach leaves you with a mid-point of 0 and the upper and lower bounds are constrained to positive and negative 5 respectively. For example, let's imagine an incredibly "positive" string with 200 tokens and where each token has an AFINN score of 5. Our resulting comparative score would look like this:

(max positive score * number of tokens) / number of tokens  
(5 * 200) / 200 = 5  

Contribute

If you have any suggestions, improvements or issues, feel free to contribute to this project. You can either submit a new issue or propose a pull request. Direct your pull requests into the dev branch.

License

Dart Sentiment is released under the MIT License

Credit

Dart Sentiment inspired by the Javascript package sentiment

About me

I am India based flutter developer

pub package twitter website

You might also like...

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter

Code partially generated with chopper 📣 Build dart types from Swagger/OpenAPI schemas SwaggerDartCodeGenerator is a code generator that looks for *.s

Jan 5, 2023

Parser builder - Lightweight template-based parser build system. Simple prototyping. Comfortable debugging. Effective developing

parser_builder Lightweight template-based parser build system. Simple prototypin

Dec 1, 2022

Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

Dec 20, 2022

Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

Dec 28, 2022

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Jan 2, 2023

AOP for Flutter(Dart)

AOP for Flutter(Dart)

AspectD Salute to AspectJ. AspectD is an AOP(aspect oriented programming) framework for dart. Like other traditional aop framework, AspectD provides c

Jan 7, 2023

Environment specific config generator for Dart and Flutter applications during CI/CD builds

Environment Config Generator Environment specific config generator. Allows to specify env configuration during CI/CD build. Primarily created to simpl

Dec 2, 2022

A Very Good Command Line Interface for Dart created by Very Good Ventures 🦄

A Very Good Command Line Interface for Dart created by Very Good Ventures 🦄

Very Good CLI Developed with 💙 by Very Good Ventures 🦄 A Very Good Command Line Interface for Dart. Installing $ dart pub global activate very_good_

Jan 8, 2023

🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

Flutter Gen Zeplin Extension 🚀 The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time. ⬇ 1.1k Getti

Oct 12, 2022
Comments
  • Repetitive words count/ French not scoring correctly

    Repetitive words count/ French not scoring correctly

    • Even when a positivo word is repeatedly found, it counts, i don't know if this is correct.

    • Not scoring positive words for French ( did not test other languages to check if they have the same problem) image

    opened by julianoventola 1
Owner
Akash Lilhare
Akash Lilhare
Morphological analysis of Japanese sentences. This Flutter plugin helps you to analyze Japanese sentences.

ringo ringo is japanese word separator. Usage final ringo = await Ringo.init(); final tokenized = ringo.tokenize('吾輩はRingoである'); print('tokenized: $to

ryo 8 Oct 31, 2022
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios.

cedvdb 39 Dec 31, 2022
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Phone Numbers Parser Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios. The advantage of this lib

cedvdb 39 Dec 31, 2022
Future based HTTP client for the Dart and Flutter

Uno Future based HTTP client for the Dart and Flutter. Uno, inspired by Axios, bringing a simple and robust experience to the crossplatform apps in Fl

Flutterando 56 Dec 16, 2022
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs. Inspired by SwiftGen. Motivation Using asset path str

FlutterGen 1.1k Jan 6, 2023
A few handy Flutter tools, dead simple `UriRouter` for `Uri`-based navigator or `BuildTracker` to track widget rebuilds and what caused them to rebuild.

noob A few handy tools for Flutter apps. UriRouter Hooks Providers PointerIndicator BuildTracker PeriodicListenable UriRouter Dead simple Uri-based pa

null 6 Jan 18, 2022
A code generation tool based on Database. :construction: developing :construction:

dbgen A code generation tool based on Database. Getting Started This project is a starting point for a Flutter application. A few resources to get you

尽管如此世界依然美丽 12 Jun 8, 2022
A high-performance, web standards-compliant rendering engine based on Flutter.

A high-performance, web standards-compliant rendering engine based on Flutter.

OpenKraken 4.8k Dec 30, 2022
A mobile map based application to help people everywhere around the world get help

Wonder This is a mobile application made by flutter. The application is called "Wonder" because it will help people everywhere around the world to get

Sara Nersisian 1 Dec 2, 2021