I have a data.frame
that has week numbers, week
, and text reviews, text
. I would like to treat the week
variable as my grouping variable and run some basic text analysis on it (e.g. qdap::polarity
). Some of the review text have multiple sentences; however, I only care about the week's polarity "on-the-whole".
How can I chain together multiple text transformations before running qdap::polarity
and adhere to its warning messages? I am able to chain together transformations with the tm::tm_map
and tm::tm_reduce
-- is there something comparable in qdap
? What is the proper way to pre-treat/transform this text prior to running qdap::polarity
and/or qdap::sentSplit
?
More details in the following code / reproducible example:
library(qdap)
library(tm)
df <- data.frame(week = c(1, 1, 1, 2, 2, 3, 4),
text = c("This is some text. It was bad. Not good.",
"Another review that was bad!",
"Great job, very helpful; more stuff here, but can't quite get it.",
"Short, poor, not good Dr. Jay, but just so-so. And some more text here.",
"Awesome job! This was a great review. Very helpful and thorough.",
"Not so great.",
"The 1st time Mr. Smith helped me was not good."),
stringsAsFactors = FALSE)
docs <- as.Corpus(df$text, df$week)
funs <- list(stripWhitespace,
tolower,
replace_ordinal,
replace_number,
replace_abbreviation)
# Is there a qdap function that does something similar to the next line?
# Or is there a way to pass this VCorpus / Corpus directly to qdap::polarity?
docs <- tm_map(docs, FUN = tm_reduce, tmFuns = funs)
# At the end of the day, I would like to get this type of output, but adhere to
# the warning message about running sentSplit. How should I pre-treat / cleanse
# these sentences, but keep the "week" grouping?
pol <- polarity(df$text, df$week)
## Not run:
# check_text(df$text)