nltk.tokenize.WordPunctTokenizer¶
- class nltk.tokenize.WordPunctTokenizer[source]¶
Bases:
RegexpTokenizer
Tokenize a text into a sequence of alphabetic and non-alphabetic characters, using the regexp
\w+|[^\w\s]+
.>>> from nltk.tokenize import WordPunctTokenizer >>> s = "Good muffins cost $3.88\nin New York. Please buy me\ntwo of them.\n\nThanks." >>> WordPunctTokenizer().tokenize(s) ['Good', 'muffins', 'cost', '$', '3', '.', '88', 'in', 'New', 'York', '.', 'Please', 'buy', 'me', 'two', 'of', 'them', '.', 'Thanks', '.']
- span_tokenize(text)[source]¶
Identify the tokens using integer offsets
(start_i, end_i)
, wheres[start_i:end_i]
is the corresponding token.- Return type
Iterator[Tuple[int, int]]