% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/semantic_analysis.R
\name{sentiment_lexicon_analysis}
\alias{sentiment_lexicon_analysis}
\title{Analyze Sentiment Using Tidytext Lexicons}
\usage{
sentiment_lexicon_analysis(
  dfm_object,
  lexicon = "bing",
  texts_df = NULL,
  feature_type = "words",
  ngram_range = 2,
  texts = NULL
)
}
\arguments{
\item{dfm_object}{A quanteda DFM object (unigram)}

\item{lexicon}{Lexicon to use: "afinn", "bing", or "nrc" (default: "bing")}

\item{texts_df}{Optional data frame with original texts and metadata (default: NULL)}

\item{feature_type}{Feature space: "words" (unigrams). The AFINN/Bing/NRC lexicons are
unigram lexicons; "ngrams" falls back to unigram scoring with a warning (default: "words").}

\item{ngram_range}{Retained for backward compatibility; not used for scoring (default: 2)}

\item{texts}{Optional character vector of texts used to rebuild a unigram DFM (default: NULL)}
}
\value{
A list containing:
\describe{
\item{document_sentiment}{Data frame with sentiment scores per document}
\item{emotion_scores}{Data frame with emotion scores (NRC only)}
\item{summary_stats}{List of summary statistics}
\item{feature_type}{Feature type used for analysis}
}
}
\description{
Performs lexicon-based sentiment analysis on a DFM object using tidytext lexicons.
Supports AFINN, Bing, and NRC lexicons with scoring and emotion analysis.

Tokens absent from the lexicon are ignored (not treated as neutral);
\code{summary_stats$token_match_rate} reports the share of corpus tokens
the lexicon covered. AFINN classification uses a +/- 0.5 band on the
per-sentiment-word average (\code{avg_sentiment}); its
\code{n_sentiment_words} column counts matched sentiment tokens, not
document length.
}
\examples{
\donttest{
abstracts <- TextAnalysisR::SpecialEduTech$abstract[1:10]
corpus <- quanteda::corpus(abstracts)
dfm_object <- quanteda::dfm(quanteda::tokens(corpus))
lexicon_results <- sentiment_lexicon_analysis(dfm_object, lexicon = "bing")
print(lexicon_results$document_sentiment)
}
}
\concept{sentiment}
