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+') |
NewerOlder