我有一个data.frame
有周数,week
和文本评论,text
。我想将该week
变量视为我的分组变量并对其进行一些基本的文本分析(例如qdap::polarity
)。一些评论文本有多个句子;但是,我只关心本周的“整体”极性。
如何在运行之前将多个文本转换链接在一起qdap::polarity
并遵守其警告消息?我能够将转换与 - 链接在一起tm::tm_map
-tm::tm_reduce
有什么可比的qdap
吗?qdap::polarity
在运行和/或之前预处理/转换此文本的正确方法是什么qdap::sentSplit
?
以下代码/可重现示例中的更多详细信息:
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)