Skip to content

Sentiment Dart is a dart module that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text. Sentiment Dart heavily inspired by the Javascript package sentiment

License

Notifications You must be signed in to change notification settings

timbrueckner/sentiment_dart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Dart

This is a fork of the sentiment_dart package. It introduces sound null safety and improves the loading of analysis data for subsequent sentiment calls of the analysis method. It also provides an extended wordlist for German.

Sentiment Dart is a dart module that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text. Sentiment Dart heavily inspired by the Javascript package sentiment

Usage

import 'package:sentiment_dart/sentiment_dart.dart';

main() {
  void main() {
    // using the default sentiment analysis (English)
    final defaultSentiment = Sentiment();
    print(defaultSentiment.analysis('i hate you piece of shit 💩'));

    // using the default sentiment analysis (English) with Emoji support
    final emojiSentiment = Sentiment(analyzeEmojis: true);
    print(emojiSentiment.analysis('i hate you piece of shit 💩'));
  }
}

output

SentimentAnalysis{score: -7, comparative: -1.1666666666666667, words: [i, hate, you, piece, of, shit], goodWords: [], badWords: [SentimentMatch{word: hate, value: -3}, SentimentMatch{word: shit, value: -4}]}

SentimentAnalysis{score: -8, comparative: -1.1428571428571428, words: [i, hate, you, piece, of, shit, 💩], goodWords: [], badWords: [SentimentMatch{word: hate, value: -3}, SentimentMatch{word: shit, value: -4}, SentimentMatch{word: 💩, value: -1}]}

Other language

example

import 'package:sentiment_dart/sentiment_dart.dart';

main() {
  void main() {
    // using the Italian sentiment analysis
    final italianSentiment = Sentiment(languageCode: 'it');
    print(italianSentiment.analysis('ti odio un pezzo di merda 💩'));

    // using the Italian sentiment analysis with Emoji support
    final italianEmojiSentiment = Sentiment(
      languageCode: 'it',
      analyzeEmojis: true,
    );
    print(italianEmojiSentiment.analysis('ti odio un pezzo di merda 💩'));
  }
}

output

SentimentAnalysis{score: -7, comparative: -1.1666666666666667, words: [ti, odio, un, pezzo, di, merda], goodWords: [], badWords: [SentimentMatch{word: odio, value: -3}, SentimentMatch{word: merda, value: -4}]}

SentimentAnalysis{score: -8, comparative: -1.1428571428571428, words: [ti, odio, un, pezzo, di, merda, 💩], goodWords: [], badWords: [SentimentMatch{word: odio, value: -3}, SentimentMatch{word: merda, value: -4}, SentimentMatch{word: 💩, value: -1}]}

Custom language

example

import 'package:sentiment_dart/sentiment_dart.dart';

main() {
  void main() {
    // using a custom map to analyse the text
    final customData = {'i': 1, 'love': 1, 'dart': 5, 'car': 2};
    final customSentiment = Sentiment(customSentiments: customData);
    print(customSentiment.analysis('i love dart'));
  }
}

output

SentimentAnalysis{score: 7, comparative: 2.3333333333333335, words: [i, love, dart], goodWords: [SentimentMatch{word: i, value: 1}, SentimentMatch{word: love, value: 1}, SentimentMatch{word: dart, value: 5}], badWords: []}

How it works ?

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.

source

Languages and code

| language | code | | -- | -- | | English | en | | Italian | it | | french | fr | | german | de |

As soon as possible, more languages will be available.

Todo

  • add more languages
  • fix small bugs
  • add support for negation

Support / Questions / Development

This forked dart package is currently used for internal development by a cup of software . We might push it to pub.dev some day if you have any questions, feel free to contact us.

About

Sentiment Dart is a dart module that uses the AFINN-165 wordlist and Emoji Sentiment Ranking to perform sentiment analysis on arbitrary blocks of input text. Sentiment Dart heavily inspired by the Javascript package sentiment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 100.0%