2016-12-07 18 views
1

私は、「kind」と「Kindertoekomst」を含むコーパス内のすべての単語を置き換えたいと思います。私は正常にそれをすることができます:R:データマイニング。部分文字列を含む単語の置換

Woorden<-c("kinderen", "kleinkind") 
Woorden[grepl("kind", Woorden)]<-"Kindertoekomst" 

しかし、私はコーパス内でそれをしたいと思います。

私は

Kind<-grepl("kind", Woorden) 
docs <- tm_map(docs, function(x) stri_replace_all_fixed(x, Woorden[as.logical(Kind)], "kindertoekomst", vectorize_all = FALSE)) 

でこれを行うために管理しかし、私はもう他の機能を使用することはできません。

dtm <- DocumentTermMatrix(docs) 

エラー:(DOC、 "TextDocument")を継承TRUE

ではありません

および corpus_clean < - tm_map(docs、content_transformer(tolower)) UseMethod( "content"、x)のエラー: 「コンテンツ」の該当メソッドがクラス「文字」

のオブジェクトに適用されていない私を助けてください:)

答えて

1

この動作するはずです:中content_transformer()機能ラッパーを使用しています

docs <- tm_map(docs, function(x) stri_replace_all_fixed(x, Woorden[as.logical(Kind)], "kindertoekomst", vectorize_all = FALSE)) 
docs <- tm_map(docs, PlainTextDocument) 
dtm <- DocumentTermMatrix(docs) 
0

を代替アプローチtmパッケージ

library(tm) 

Woorden<-c("kinderen", "kleinkind") 

rep_kind <- function(x){ 
    gsub("\b.*kind.*\b","Kindertoekomst",x) 
} 

docs <- Corpus(VectorSource(as.list(Woorden))) 
docs <- tm_map(docs, content_transformer(rep_kind)) 
dtm <- DocumentTermMatrix(docs) 
inspect(dtm) 
関連する問題