步骤 3:文本整理

使用 R 的 Bag-of-Words 进行文本挖掘

Ted Kwartler

Instructor

用 qdap 进行文本整理

# qdap 清洗函数
qdap_clean <- function(x) {
  x <- replace_abbreviation(x)
  x <- replace_contraction(x)
  x <- replace_number(x)
  x <- replace_ordinal(x)
  x <- replace_symbol(x)
  x <- tolower(x)
  return(x)
}
使用 R 的 Bag-of-Words 进行文本挖掘

用 tm 进行文本整理

# tm 清洗函数
tm_clean <- function(corpus) {
  tm_clean <- tm_map(corpus, removePunctuation)
  corpus <- tm_map(corpus, stripWhitespace)
  corpus <- tm_map(corpus, removeWords,
              c(stopwords("en"), "Google", "Amazon", "company"))
  return(corpus)
}
使用 R 的 Bag-of-Words 进行文本挖掘

清洗语料库

 

清洗语料.png

使用 R 的 Bag-of-Words 进行文本挖掘

开始练习!

使用 R 的 Bag-of-Words 进行文本挖掘

Preparing Video For Download...