Sea*_*n M 5 text r text-analysis text-mining
我有带有评论栏的调查数据。我正在寻找对回复的情绪分析。问题是数据中有很多语言,我不知道如何从集合中消除多种语言停用词
'nps' 是我的数据源,nps$customer.feedback 是评论栏。
首先我对数据进行标记
#TOKENISE
comments <- nps %>%
filter(!is.na(cusotmer.feedback)) %>%
select(cat, Comment) %>%
group_by(row_number(), cat)
comments <- comments %>% ungroup()
Run Code Online (Sandbox Code Playgroud)
摆脱停用词
nps_words <- nps_words %>% anti_join(stop_words, by = c('word'))
Run Code Online (Sandbox Code Playgroud)
然后使用 Stemming 和 get_sentimets("bing") 按情绪显示字数。
#stemgraph
nps_words %>%
mutate(word = wordStem(word)) %>%
inner_join(get_sentiments("bing") %>% mutate(word = wordStem(word)), by =
c('word')) %>%
count(cat, word, sentiment) %>%
group_by(cat, sentiment) %>%
top_n(7) %>%
ungroup() %>%
ggplot(aes(x=reorder(word, n), y = n, fill = sentiment)) +
geom_col() +
coord_flip() +
facet_wrap( ~cat, scales = "free") +
scale_fill_brewer(palette = "Set1") +
labs(title = "Word counts by Sentiment by Category - Bing (Stemmed)", x =
`"Words", y = "Count")`
Run Code Online (Sandbox Code Playgroud)
然而,由于正在分析德语文本,“di”和“die”出现在“负”图中。
有人可以帮忙吗?
我的目标是使用上面的代码消除德语停用词。
要回答您的问题,您可以这样做来删除德语停用词。使用停用词包:
your code
.....
stop_german <- data.frame(word = stopwords::stopwords("de"), stringsAsFactors = FALSE)
nps_words <- nps_words %>%
anti_join(stop_words, by = c('word')) %>%
anti_join(stop_german, by = c("word"))
...
rest of code
Run Code Online (Sandbox Code Playgroud)
但是,请意识到 tidytext 主要适用于英语,而不适用于其他语言。使用德语文本进行词干分析和情感分析会给您带来不正确的结果。Bing情感仅适用于英文单词。像您一样执行inner_join将删除大部分德语单词,因为在英语中没有匹配的单词。但有些匹配,例如“die”一词(如果您使用德语停用词,则将其删除,意思是“谁”或“那个人”)。但如果你删除这个词,你可能会不小心删除英文“die”(死亡)。
这篇 SO 文章提供了有关德国情绪分析的更多信息。