2017-09-21 5 views
0

ステム付きのすべての単語のリストを元のフォームと共に取得しようとしています。stemDocumentをRで実行した後、元のformとともにすべてのステム付き単語のリストを取得する方法

は、ここで私はこれがあなたのために役立つものになることがあり、データフレームに、このような答えを

orginal_word stemmed 
Impressed  Impress 
shipping  ship 
very   veri 
helpful   help 
wonderful  wonder 
experience  experi 

答えて

0

を探しています例

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 
+0

おそらく 'wordStem(word、" english ")'が必要です。ポーターステムマー。 –

0

library("corpus") 
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") 
word <- text_types(text, collapse = TRUE, drop = stopwords_en, drop_punct = TRUE) 
stem <- SnowballC::wordStem(word, "english") 
data.frame(word, stem) 

結果:

  word stem 
1  arrived arriv 
2  days  day 
3  earlier earlier 
4 expected expect 
5 experience experi 
6  helpful help 
7 impressed impress 
8 shipping ship 
9  time time 
10 wonderful wonder 

(それがあなたにとって重要ならばtext_types機能もtmコーパスオブジェクトを受け入れます。)

関連する問題