を探しています例
library(tm)
text <- c("Very Impressed with the shipping time, it arrived a few days earlier than expected", "it was very helpful","It was a wonderful experience")
corpus<-Corpus(VectorSource(text))
corpus<-tm_map(corpus,stemDocument)
です。 SnowballC
パッケージには、wordStem()
という機能があります。それを使用すると、次のことができます。 tidytext
パッケージにunnest_tokens()
を使用しているので、最初にデータフレームを作成しました。この関数は単語を分割し、ロングフォーマットのデータセットを作成します。停止語を削除したいので、filter()
を使用しました。最終ステップはあなたにとって重要なものです。私はSnowballC
パッケージにwordStem()
を使用して、データに残っている単語のステムを抽出しました。結果は、あなたが望むものと正確に同じではないかもしれません。しかし、これがある程度助けてくれることを願っています。これは、もう少し効率的@ jazzurroの答えよりも
library(dplyr)
library(tidytext)
library(SnowballC)
mydf <- data_frame(id = 1:length(text),
text = text)
data(stop_words)
mydf %>%
unnest_tokens(input = text, output = word) %>%
filter(!word %in% stop_words$word) %>%
mutate(stem = wordStem(word))
# id word stem
# <int> <chr> <chr>
# 1 1 impressed impress
# 2 1 shipping ship
# 3 1 time time
# 4 1 arrived arriv
# 5 1 days dai
# 6 1 earlier earlier
# 7 1 expected expect
# 8 2 helpful help
# 9 3 wonderful wonder
#10 3 experience experi
おそらく 'wordStem(word、" english ")'が必要です。ポーターステムマー。 –