module Cadmium::Sentiment

Overview

Uses sentiment analysis to score a sentence's "feeling". Cadmium::Sentiment also takes advantage of emojis to further increase accuracy.

Extended Modules

Defined in:

cadmium/sentiment.cr

Constant Summary

NEGATORS = {"cant" => 1, "can't" => 1, "dont" => 1, "don't" => 1, "doesnt" => 1, "doesn't" => 1, "not" => 1, "non" => 1, "wont" => 1, "won't" => 1, "isnt" => 1, "isn't" => 1, "wasnt" => 1, "wasn't" => 1}

Negate the next word in the phrase.

Class Method Summary

Instance Method Summary

Class Method Detail

def self.data=(data : String?) #

Set the sentiment data. Format should look like:

convince	1
cover-up	-3
cramp	-1

Where higher numbers are more positive, lower numbers are more negative, and 0 is neutral.


[View source]
def self.sentiment_data #

Gets the raw sentiment data.


[View source]
def self.tokenizer : Cadmium::Tokenizer #

Manage the Tokenizer that the sentiment analyzer uses.


[View source]
def self.tokenizer=(tokenizer : Cadmium::Tokenizer) #

Manage the Tokenizer that the sentiment analyzer uses.


[View source]

Instance Method Detail

def analyze(phrase, inject = nil) #

Analyze a phrase and return a result hash comprised of a score, comparative analysis (a score based soley on number of negative and positive words), tokens, words, positive (positive words), and negative (negative words).

pp Cadmium::Sentiment.analyze("You are a piece of 💩")
# => {score: -1,
#     comparative: -1,
#     tokens: ["You", "are", "a", "piece", "of", "💩"],
#     words: ["💩"],
#     positive: [],
#     negative: ["💩"]}

[View source]