如何在text2vec中包含stopwords(术语)

如何在text2vec中包含stopwords(术语),r,text-mining,text2vec,R,Text Mining,Text2vec,在text2vec包中,我正在使用create_词汇表函数。例如: 我的课文是“这本书很好”,假设我没有使用stopwords和1L到3L的ngram。所以vocab术语将是 这本书是非常好的这本书,。。。。。这本书非常非常好。我只想删除术语“book is very”(以及大量使用向量的其他术语)。因为我只想删除一个短语,所以我不能使用stopwords。我已将以下代码编码: vocab<-create_vocabulary(it,ngram=c(1L,3L)) vocab_mod<

text2vec
包中,我正在使用create_词汇表函数。例如: 我的课文是“这本书很好”,假设我没有使用stopwords和1L到3L的ngram。所以vocab术语将是

这本书是非常好的这本书,。。。。。这本书非常非常好。我只想删除术语“book is very”(以及大量使用向量的其他术语)。因为我只想删除一个短语,所以我不能使用stopwords。我已将以下代码编码:

vocab<-create_vocabulary(it,ngram=c(1L,3L))
vocab_mod<- subset(vocab,!(term %in% stp) # where stp is stop phrases.

x<- read.csv(Filename') #these are all stop phrases
stp<-as.vector(x$term)

vocab似乎
subset
函数删除了一些属性。您可以尝试:

library(text2vec)
txt = "This book is very good"
it = itoken(txt)
v = create_vocabulary(it, ngram = c(1, 3))
v = v[!(v$term %in% "is_very_good"), ]    
v
# Number of docs: 1 
# 0 stopwords:  ... 
# ngram_min = 1; ngram_max = 3 
# Vocabulary: 
#   term term_count doc_count
# 1:         good          1         1
# 2: book_is_very          1         1
# 3:    This_book          1         1
# 4:         This          1         1
# 5:         book          1         1
# 6:    very_good          1         1
# 7:      is_very          1         1
# 8:      book_is          1         1
# 9: This_book_is          1         1
# 10:           is          1         1
# 11:         very          1         1
dtm = create_dtm(it, vocab_vectorizer(v))

@Dmitry即使这样也可以删除属性。。。所以我找到的解决方法就是现在使用attr函数手动添加属性

attr(语音模块,“ngram”)