Created
July 29, 2017 12:29
Word processing for a bayesian spam filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_words | |
# Lowercase | |
words.each &:downcase! | |
# Remove punctuation | |
words.map! { |word| word.gsub(/[^a-z0-9\s]/i, '') } | |
# Remove numbers | |
words.map! { |word| word.gsub(/[0-9]/i, '') } | |
# Remove empty and single-letter words | |
words.reject! { |word| word.length < 2 } | |
# Remove stopwords | |
@words -= stopwords | |
# Stemming | |
words.map! { |word| stemmer.stem(word) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment