Created
December 4, 2014 19:26
-
-
Save samsondav/e1951194a287e46cbda2 to your computer and use it in GitHub Desktop.
Tokenize an abitrary Spanish string into words
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 self.tokenize_spanish(text) | |
text = text.sub(/(https?:\/\/[\S]*[$\z\s])/i, '') # strip urls | |
words = text.scan(/[\w@#ñÑáÁéÉíÍóÓúÚü]+/) # tokenize into words | |
words.map! {|word| word.downcase} # lowercase everything | |
words.reject! {|word| word.length < 4} # reject words with 3 or fewer characters | |
return words | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment