Text Analysis - Sentiment

From Q
Jump to navigation Jump to search
Related Videos

Chapter within Text Analysis in Q5 (Video)

 

Generate a variable which assigns scores to a set of text responses which attempts to quantify how positive or negative each response is. This can be done based on raw text in the data set, or it can be based on text which has been processed using Text Analysis - Advanced - Setup Text AnalysisInsert > Text Analysis > Advanced > Setup Text Analysis.

This blog post describes how sentiment scores can be visualized with word clouds.

Text entries which were originally blank will get a missing value for the sentiment score and so will be excluded from the base. You can recode them in the usual way, by right-clicking the table with your sentiment scores and selecting Values (...), and then changing the value from NaN to 0.

Background

This R item uses dictionaries of positive and negative English-language words to generate the score for each response. Positive words in the text each add a score of 1, negative words add a score of -1, and the final score is obtained by summing these up. The scoring heuristic also attempts to identify when sentiment has been negated, for example not good would generate a score of -1 instead of a score for 1. Positive and negative words are based on modified lists from here: | https://www.cs.uic.edu/~liub/FBS/sentiment-analysis.html#lexicon

Usage

To generate scores in the data set, select either a SUMMARY table showing Text data, a variable in the Data tree containing Text data, or an text-processing item generated in your report using Text Analysis - Advanced - Setup Text AnalysisInsert > Text Analysis > Advanced > Setup Text Analysis.

Code

var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};

// The require function
function __webpack_require__(moduleId) {

// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);

// Return the exports of the module
return module.exports;

}

// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
// This version is to enable sentiment analysis in Q
// button for Text variables.
includeWeb("QScript Sentiment Analysis Functions");

saveSentimentScores();