Learn R Programming

sumup (version 1.0.1)

sentiment_analysis_sentimentr: Sentiment Analysis using sentimentr

Description

This function performs sentiment analysis on sentences using a predefined lexicon and the sentimentr package. The sentiment score is calculated based on a dictionary of words with associated sentiment values.

Usage

sentiment_analysis_sentimentr(
  documents,
  sentences,
  dictionary_file,
  use_dictionary_file_in_sentimentr
)

Value

A data table with the following columns:

  • sentenceid: The ID of the sentence.

  • sentence: The sentence being analyzed.

  • polarity: The sentiment polarity score for the sentence.

  • document: The document identifier to which the sentence belongs.

Arguments

documents

A character vector of document identifiers for which sentiment analysis needs to be performed. This is included for consistency, but is not directly used in the analysis.

sentences

A data frame containing sentence-level data. It should include the following columns:

  • sentenceid: The unique identifier of the sentence.

  • sentence: The sentence text that needs to be analyzed.

  • document: The identifier of the document to which the sentence belongs.

dictionary_file

A string representing the path to a CSV file containing the sentiment dictionary. The file should have two columns:

  • word: The words in the lexicon.

  • value: The sentiment value associated with the word.

use_dictionary_file_in_sentimentr

A boolean determining whether the dictionary file is used (TRUE) or the built-in lexicon (FALSE)

Details

This function loads a sentiment dictionary, processes the sentences, and calculates a sentiment score for each sentence using the sentimentr package. The dictionary is expected to have words associated with sentiment values that influence the sentiment score calculation. Positive sentiment scores indicate a positive sentiment, while negative values indicate negative sentiment.

The dictionary file (SumUp_Dictionary.csv) is read from the data/ directory by default. The file should have a column of words and corresponding sentiment values.