Last active
August 29, 2015 14:23
-
-
Save fran0x/c307fc79dd2bdd2ecd91 to your computer and use it in GitHub Desktop.
Simple word tokenizer that returns a list of non-empty words in lowercase
This file contains hidden or 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 simpleWordTokenizer(string): | |
""" A simple (for-comprehension) implementation of input string tokenization | |
Args: | |
string (str): input string | |
Returns: | |
list: a list of tokens in lowercase and no empty strings | |
""" | |
return [x for x in re.split(split_regex, string.lower()) if x] | |
starWarsDarkSide = 'Only at the end do you realize the power of the Dark Side.' | |
print simpleWordTokenizer(starWarsDarkSide) # should give ['only', 'at', 'the', 'end', 'do', 'you', 'realize', 'the', 'power', ...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment