Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

dart sentiment

flutter community: dart_sentiment

pub package AFINN-based sentiment analysis for dart

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: <latest-version>

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 AFINN-based sentiment analysis for dart twitter website


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top