在 tidyr 中提取 ngram
stemming ngrams in tidyr
我正在尝试创建同时包含两个词干的双字母组。但是我的代码只提取第二个词的词干,而第一个词没有词干。因此,例如 "worrying about" 和 "worry about" 是分开列出的。
如有任何帮助,我们将不胜感激。
bigram_text <- text_df %>%
mutate_all(as.character) %>%
unnest_tokens(bigram, text, token = "ngrams", n = 2)%>%
mutate(bigram = wordStem(bigram))
bigramcount<- bigram_text %>%
count(bigram, sort = TRUE)
您面临的问题是 wordStem
和许多其他词干提取器只提取词干。你想要阻止一个 bigram,它是 2 个单词。你需要的是使用一个可以阻止句子的特定函数。在这种情况下,您可以使用包 textstem 中名为 stem_strings
的函数。
library(textstem)
bigram_text <- text_df %>%
mutate_all(as.character) %>%
unnest_tokens(bigram, text, token = "ngrams", n = 2)%>%
mutate(bigram = stem_strings(bigram))
当然,更迂回的方法是将二元组拆分为 2 列,对列进行截干,然后将它们重新粘贴在一起。
我正在尝试创建同时包含两个词干的双字母组。但是我的代码只提取第二个词的词干,而第一个词没有词干。因此,例如 "worrying about" 和 "worry about" 是分开列出的。
如有任何帮助,我们将不胜感激。
bigram_text <- text_df %>%
mutate_all(as.character) %>%
unnest_tokens(bigram, text, token = "ngrams", n = 2)%>%
mutate(bigram = wordStem(bigram))
bigramcount<- bigram_text %>%
count(bigram, sort = TRUE)
您面临的问题是 wordStem
和许多其他词干提取器只提取词干。你想要阻止一个 bigram,它是 2 个单词。你需要的是使用一个可以阻止句子的特定函数。在这种情况下,您可以使用包 textstem 中名为 stem_strings
的函数。
library(textstem)
bigram_text <- text_df %>%
mutate_all(as.character) %>%
unnest_tokens(bigram, text, token = "ngrams", n = 2)%>%
mutate(bigram = stem_strings(bigram))
当然,更迂回的方法是将二元组拆分为 2 列,对列进行截干,然后将它们重新粘贴在一起。