Created
March 6, 2012 21:39
-
-
Save brunoadacosta/1989104 to your computer and use it in GitHub Desktop.
CommentsNormalizer
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
class CommentsNormalizer | |
BLACK_LIST = ["arma", "carro"] | |
SPECIAL_CHARS = { | |
"@" => "a", | |
"4" => "a", | |
"0" => "o", | |
"3" => "e", | |
"1" => "i", | |
"." => "", | |
"5" => "s" | |
} | |
def self.normalize(comment) | |
normalized_comment = [] | |
comment.split(" ").each do |word| | |
word_with_no_special_char = self.remove_special_chars word | |
to_be_ommited = word_with_no_special_char if self.need_to_omitted? word_with_no_special_char | |
to_be_ommited = word_with_no_special_char.squeeze if self.need_to_omitted? word_with_no_special_char.squeeze | |
word = self.omit_blacklisted_words to_be_ommited if to_be_ommited | |
normalized_comment << word | |
end | |
normalized_comment.join(" ") | |
end | |
def self.remove_special_chars(word) | |
SPECIAL_CHARS.each do |special_char, letter| | |
word = word.gsub(special_char, letter) | |
end | |
word | |
end | |
def self.need_to_omitted?(word) | |
BLACK_LIST.include? word.downcase | |
end | |
def self.omit_blacklisted_words(word) | |
need_to_omitted?(word) ? "xxxx" : word | |
end | |
end |
Author
brunoadacosta
commented
Mar 6, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment