%% Evaluate Sentiment Using Custom Lexicon
% Sentiment analysis algorithms rely on annotated lists of words called sentiment lexicons. For example, the ratioSentimentScores function uses a sentiment lexicon with words annotated with a sentiment score ranging from -1 to 1, where scores close to 1 indicate strong positive sentiment, scores close to -1 indicate strong negative sentiment, and scores close to zero indicate neutral sentiment.
% If the sentiment lexicon used by the ratioSentimentScores function does not suit the data you are analyzing, for example, if you have a domain-specific data set like medical or engineering data, then you can use your own custom sentiment lexicon. For an example showing how to generate a domain specific sentiment lexicon, see Generate Domain Specific Sentiment Lexicon.
% Create a tokenized document array containing the text data to analyze.

textData = [ 
    "This company is showing extremely strong growth."
    "This other company is accused of misleading consumers."];
documents = tokenizedDocument(textData);

% Load the example domain specific lexicon for finance data.

filename = "financeSentimentLexicon.csv";
tbl = readtable(filename);
head(tbl)

% Evaluate the sentiment using the ratioSentimentScores function and specify the custom sentiment lexicon using the 'SentimentLexicon' option. 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,'SentimentLexicon',tbl)

% Copyright 2020 The MathWorks, Inc.