2017-08-18 5 views
0

文字のベクトルからストップワードを削除しようとしています。しかし、私が直面している問題は、 "king kond"という言葉があることです。 "king"はストップワードの1つで、 "kong kong"の "king"は削除されています。tmがダブルワードからストップワードを削除しないようにします。

ダブルワードが削除されないようにする手段はありますか? 私のコードは次のとおりです。

text <- VCorpus(VectorSource(newmnt1$form)) 
#(newmnt1$form is chr [1:4] "king kong lives" "foot" "island" "skull") 

#Normal standardization of text. 
text <- tm_map(text, content_transformer(tolower)) 
text <- tm_map(text, removeWords, custom_stopwords) 
text <- tm_map(text, stripWhitespace) 
newmnt2 <- text[[1]]$content 

答えて

1

一つの迅速なハックがあなたの「キングコング」のパターンを変えることであろうに「king_kong」。

a <- gsub("king kong", "king_kong", "This is a pattern with king and king kong") 
a 
[1] "This is a pattern with king and king_kong" 

tm::removeWords(a, "king") 
[1] "This is a pattern with and king_kong" 

ベスト、

コリン・

0

あなたが別のパッケージを使用するために喜んでいる場合は、この作品:

> text <- c("king kong lives", "foot", "island", "skull", "This is a pattern with king and king kong") 
> corpus::term_matrix(text, drop = "king", combine = "king kong", transpose = TRUE) 
11 x 5 sparse Matrix of class "dgCMatrix" 

a   . . . . 1 
and  . . . . 1 
foot  . 1 . . . 
is  . . . . 1 
island . . 1 . . 
king kong 1 . . . 1 
lives  1 . . . . 
pattern . . . . 1 
skull  . . . 1 . 
this  . . . . 1 
with  . . . . 1 

combine引数は、ようking kongを解釈するコーパスに指示単一のトークン。

関連する問題