Text Mining Basics
Stopword Filter
Keep Content Words
Stopword filtering removes common words so the remaining tokens carry more topic signal.
Program
Play the script to choose a stopword set and compare the remaining content tokens.
stopword_filter.R
Replay: real traced execution (multi-file project)
tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")
stop_choice <- 1
stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))
stopwords <- stop_sets[[stop_choice]]
content <- tokens[!(tokens %in% stopwords)]
summary <- paste(content, collapse = ",")
cat(summary, "\n", sep = "")
tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")
stop_choice <- 2
stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))
stopwords <- stop_sets[[stop_choice]]
content <- tokens[!(tokens %in% stopwords)]
summary <- paste(content, collapse = ",")
cat(summary, "\n", sep = "")
tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")
stop_choice <- 3
stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))
stopwords <- stop_sets[[stop_choice]]
content <- tokens[!(tokens %in% stopwords)]
summary <- paste(content, collapse = ",")
cat(summary, "\n", sep = "")
tokens ← data, is, useful, when, data, answers, questions
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 1values this stepdata, is, useful, when, data, answers, questionstokensstop_choice ← 1
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 13stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))values this step1stop_choicestop_sets ← 3 choices
2stop_choice <- 13stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]values this step3 choicesstop_setsstopwords ← is, when
3stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]values this stepis, whenstopwords1stop_choicecontent ← data, useful, data, answers, questions
4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")values this stepdata, useful, data, answers, questionscontent7 tokenstokensis, whenstopwordssummary ← data,useful,data,answers,questions
5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")values this stepdata,useful,data,answers,questionssummary5 tokenscontentcat(summary, " ", sep = "")
6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")outputdata,useful,data,answers,questionsvalues this stepdata,useful,data,answers,questionssummary
tokens ← data, is, useful, when, data, answers, questions
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 2values this stepdata, is, useful, when, data, answers, questionstokensstop_choice ← 2
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 23stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))values this step2stop_choicestop_sets ← 3 choices
2stop_choice <- 23stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]values this step3 choicesstop_setsstopwords ← is, when, data
3stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]values this stepis, when, datastopwords2stop_choicecontent ← useful, answers, questions
4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")values this stepuseful, answers, questionscontent7 tokenstokensis, when, datastopwordssummary ← useful,answers,questions
5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")values this stepuseful,answers,questionssummary3 tokenscontentcat(summary, " ", sep = "")
6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")outputuseful,answers,questionsvalues this stepuseful,answers,questionssummary
tokens ← data, is, useful, when, data, answers, questions
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 3values this stepdata, is, useful, when, data, answers, questionstokensstop_choice ← 3
1tokens <- c("data", "is", "useful", "when", "data", "answers", "questions")2stop_choice <- 33stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))values this step3stop_choicestop_sets ← 3 choices
2stop_choice <- 33stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]values this step3 choicesstop_setsstopwords ← is, when, questions
3stop_sets <- list(c("is", "when"), c("is", "when", "data"), c("is", "when", "questions"))4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]values this stepis, when, questionsstopwords3stop_choicecontent ← data, useful, data, answers
4stopwords <- stop_sets[[stop_choice]]5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")values this stepdata, useful, data, answerscontent7 tokenstokensis, when, questionsstopwordssummary ← data,useful,data,answers
5content <- tokens[!(tokens %in% stopwords)]6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")values this stepdata,useful,data,answerssummary4 tokenscontentcat(summary, " ", sep = "")
6summary <- paste(content, collapse = ",")7cat(summary, "\n", sep = "")outputdata,useful,data,answersvalues this stepdata,useful,data,answerssummary
stopwords
Stopwords are tokens the analysis chooses to ignore.
list
`stop_sets[[stop_choice]]` picks one candidate vector from a list.
%in%
`tokens %in% stopwords` marks which tokens should be removed.