ratioSentimentScores

Sentiment scores with ratio rule

Description

Use ratioSentimentScores to evaluate sentiment in tokenized text with a ratio rule. The ratioSentimentScores function uses, by default, the VADER sentiment lexicon.

example

compoundScores = ratioSentimentScores(documents) returns sentiment scores for tokenized documents based on the ratio of positive and negative tokens. For each document where the ratio of the positive score to negative score is larger than 1, the function returns 1. For each document where the ratio of the negative score to positive score is larger than 1, the function returns -1. Otherwise, the function returns 0.

[compoundScores,positiveScores,negativeScores] = ratioSentimentScores(documents)also returns the sums of the positive and negative token scores of the documents respectively.

___ = ratioSentimentScores(___,Name,Value) specifies additional options using one or more name-value pairs.

Examples

collapse all

Create a tokenized document.

str = [
    "The book was VERY good!!!!"
    "The book was terrible."];
documents = tokenizedDocument(str);

Evaluate the sentiment of the tokenized documents. A score of 1 indicates positive sentiment, a score of -1 indicates negative sentiment, and a score of 0 indicates neutral sentiment.

compoundScores = ratioSentimentScores(documents)
compoundScores = 2×1

     1
    -1

Input Arguments

collapse all

Input documents, specified as a tokenizedDocument array.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: Threshold,0.5 sets the ratio threshold to 0.5

Sentiment lexicon, specified as a table with the following columns:

  • Token – Token, specified as a string scalar.

  • SentimentScore – Sentiment score of token, specified as a numeric scalar.

The default sentiment lexicon is the VADER sentiment lexicon.

Data Types: table

Ratio threshold, specified as a nonnegative scalar.

If the ratio of the positive score to negative score of documents(i) is larger than Threshold, then compoundScores(i) is 1. If the ratio of the negative score to positive score of documents(i) is larger than Threshold, then compoundScores(i) is -1. Otherwise, compoundScores(i) is 0.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Compound sentiment scores, returned as a numeric vector. The function returns one score for each input document.

If the ratio of the positive score to negative score of documents(i) is larger than Threshold, then compoundScores(i) is 1. If the ratio of the negative score to positive score of documents(i) is larger than Threshold, then compoundScores(i) is -1. Otherwise, compoundScores(i) is 0.

Positive sentiment scores, returned as a numeric vector. The function returns one score for each input document. The value positiveScores(i) corresponds to the positive sentiment score of documents(i).

Negative sentiment scores, returned as a numeric vector. The function returns one score for each input document. The value negativeScores(i) corresponds to the negative sentiment score of documents(i).

Introduced in R2019b