Created
September 1, 2018 00:03
-
-
Save emmagrimaldi/7199a754ae6ac7366b66faa19f6ab494 to your computer and use it in GitHub Desktop.
tokens
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
| # importing the libraries needed in this section | |
| import nltk | |
| from nltk.tokenize import RegexpTokenizer | |
| # defining the text | |
| text = 'Rome was founded in 753BC by its first king, Romulus.' | |
| # instantiating the tokenizer object. By passing r'\w+' to the RegexpTokenizer | |
| # I am selecting groups of single words, discarding the punctuation | |
| tokenizer = RegexpTokenizer(r'\w+') | |
| # getting the tokens | |
| tokens = tokenizer.tokenize(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment