包tm:removeWords如果指定,如何避免删除CERTIAN(具体否定)"英语"停用词?

Rob*_*ert 3 r corpus stop-words tm

我想通过以下方式使用removeWords(stopwords("english"))函数:corpus <- tm_map(corpus,removeWords, stopwords("english"))但是有些像"不"这样的词,以及其他我想保留的否定.

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

我怎么能阻止删除"不"例如?

(二级)是否可以将此类控制列表设置为所有"否定"?

我宁愿不使用我感兴趣的停止列表中的单词来创建我自己的自定义列表.

Duf*_*f59 5

您可以通过区分stopwords("en")和要排除的单词列表来创建自定义停用词列表:

exceptions   <- c("not")
my_stopwords <- setdiff(stopwords("en"), exceptions)
Run Code Online (Sandbox Code Playgroud)

如果您需要删除所有否定,您可以grep从stopwords()列表中删除它们:

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)
Run Code Online (Sandbox Code Playgroud)