2015-10-27 20 views
3

我想使用removeWordsstopwords("english"))功能通过:corpus <- tm_map(corpus,removeWords, stopwords("english"))但一些词像“不”和其他否定我想保留。包tm:removeWords如何避免删除CERTIAN(否定具体)“英语”停用词如果指定?

是否可以使用removeWords, stopwords("english")函数但是如果指定排除该列表中的某些单词?

我怎样才能防止“不”,例如?

(辅助)是否可以将此类型的控件列表设置为全部“否定”?

我宁愿不诉诸于只从索引字表,我很感兴趣的话创造我自己的自定义列表。

回答

5

您可以通过采取stopwords("en")和之间的差别创建禁用词的自定义列表单词的列表,要排除:

exceptions <- grep(pattern = "not|n't", x = stopwords(), value = TRUE) 
# [1] "isn't"  "aren't" "wasn't" "weren't" "hasn't" "haven't" "hadn't" "doesn't" "don't"  "didn't" 
# [11] "won't"  "wouldn't" "shan't" "shouldn't" "can't"  "cannot" "couldn't" "mustn't" "not" 
my_stopwords <- setdiff(stopwords("en"), exceptions) 

exceptions <- c("not") 
my_stopwords <- setdiff(stopwords("en"), exceptions) 

如果您需要删除所有的否定,你可以从stopwords()列表grep他们

+0

'(stopwords(“en”)'?所以'my_stopwords < - setdiff(stopwords(“en”),例外)'或'my_stopwords < - setdiff(stopwords(“english”),例外)'? – Robert

+1

“en”或“english”给出相同的列表。 – Duf59

+0

你会碰巧知道如何在'removePunctuation'中保留撇号吗?我只是意识到我需要知道这个函数,因为我包括(')。 – Robert