Python NLTK | nltk.tokenize.SExprTokenizer()
Last Updated :
12 Jun, 2019
With the help of nltk.tokenize.SExprTokenizer()
method, we are able to extract the tokens from string of characters or numbers by using tokenize.SExprTokenizer()
method. It actually looking for proper brackets to make tokens.
Syntax : tokenize.SExprTokenizer()
Return : Return the tokens from a string of characters or numbers.
Example #1 :
In this example we can see that by using tokenize.SExprTokenizer()
method, we are able to extract the tokens from stream of characters or numbers by taking brackets in consideration.
from nltk.tokenize import SExprTokenizer
tk = SExprTokenizer()
gfg = "( a * ( b + c ))ab( a-c )"
geek = tk.tokenize(gfg)
print (geek)
|
Output :
[‘( a * ( b+c ))’, ‘ab’, ‘( a-c )’]
Example #2 :
from nltk.tokenize import SExprTokenizer
tk = SExprTokenizer()
gfg = "(a b) c d (e f)"
geek = tk.tokenize(gfg)
print (geek)
|
Output :
[‘(a b)’, ‘c’, ‘d’, ‘(e f)’]
Share your thoughts in the comments
Please Login to comment...