Introduction
This pipeline outlines a method for analyzing Hebrew textual data to extract emotional metrics, specifically Valence and Arousal scores, using the R programming language. The process begins by installing and loading a specialized package designed for Hebrew affective norms. An example dataset containing Hebrew text is then imported. A custom function is defined to process this dataset: it validates the input format, renames the text column, and applies the package’s functions to compute Valence and Arousal for each text entry individually. The function augments the original dataset by adding two new columns with these computed scores, resulting in an enriched dataset that combines the original text with its corresponding emotional assessments.
# install.packages("remotes")
remotes::install_github("almogsi/hebnoRms")
## Skipping install of 'hebnoRms' from a github remote, the SHA1 (da566bca) has not changed since last install.
## Use `force = TRUE` to force installation
library(hebnoRms)
ExRe_kosher_1 <- read.csv("ExRe_kosher_1.csv")
head(ExRe_kosher_1)
## איך.להוציא.תעודת.כשרות.בחרטא
## 1 אדם המסביר את תחום הכשרות האלטרנטיבית והסכנות שלו
## 2 עמדה של בחור דתי המציג כשרות אלטרנטיבית המבוססת על אמון. הבחור טוען כנגד כשרות זו מסיבות כלכליות ואישיות. קבלת כשרות שכזו פוגעת לטענתו בענייני הדת במדינה.
## 3 איש דתי שאומר שאין לסמוך על כשרויות אלטרנטיביות אלא רק על כשרות רבנות
## 4 בחור שמסביר את הקושי של הציבור הדתי עם הכשרות האלנטרנטיבית
## 5 מישהו שמסביר למה כשרות אלטרנטיבי זה רע
## 6 סרטון גרוע מאוד מבחינה עיצובית שבה מישהו מסביר על הסכנות הכרוחות בכך שמתחילות לקום להם כל מיני כשרויות אלטרנטיביות, ואיך זה בכלל נועד להרוס את אופי המדינה היהדות. דיבר על כך שמאוד צריך להיזהר כי תמיד יהיו כאלה שמחפפים ואין לדעת לאן זה יביא.
add_valence_arousal <- function(df) {
# Check if the dataframe has only one column
if (ncol(df) != 1) {
stop("The dataframe must have exactly one column containing Hebrew text.")
}
# Rename the single column to 'text'
colnames(df) <- "text"
# Ensure the hebnoRms package is installed and load it
if (!requireNamespace("hebnoRms", quietly = TRUE)) {
stop("The 'hebnoRms' package is required but not installed.")
}
library(hebnoRms)
# Apply get_valence and get_arousal to each text entry
df$Valence <- sapply(df$text, get_valence)
df$Arousal <- sapply(df$text, get_arousal)
# Return the updated dataframe
return(df)
}
ExRe_kosher_1_processed <- add_valence_arousal(ExRe_kosher_1)
head(ExRe_kosher_1_processed)
## text
## 1 אדם המסביר את תחום הכשרות האלטרנטיבית והסכנות שלו
## 2 עמדה של בחור דתי המציג כשרות אלטרנטיבית המבוססת על אמון. הבחור טוען כנגד כשרות זו מסיבות כלכליות ואישיות. קבלת כשרות שכזו פוגעת לטענתו בענייני הדת במדינה.
## 3 איש דתי שאומר שאין לסמוך על כשרויות אלטרנטיביות אלא רק על כשרות רבנות
## 4 בחור שמסביר את הקושי של הציבור הדתי עם הכשרות האלנטרנטיבית
## 5 מישהו שמסביר למה כשרות אלטרנטיבי זה רע
## 6 סרטון גרוע מאוד מבחינה עיצובית שבה מישהו מסביר על הסכנות הכרוחות בכך שמתחילות לקום להם כל מיני כשרויות אלטרנטיביות, ואיך זה בכלל נועד להרוס את אופי המדינה היהדות. דיבר על כך שמאוד צריך להיזהר כי תמיד יהיו כאלה שמחפפים ואין לדעת לאן זה יביא.
## Valence Arousal
## 1 5.11 4.92
## 2 5.10 5.11
## 3 5.25 5.15
## 4 4.77 4.83
## 5 4.20 4.96
## 6 5.14 4.94