📜  Python NLTK | nltk.WhitespaceTokenizer

📅  最后修改于: 2022-05-13 01:54:55.342000             🧑  作者: Mango

Python NLTK | nltk.WhitespaceTokenizer

nltk.tokenize.WhitespaceTokenizer()方法的帮助下,我们可以使用tokenize.WhitespaceTokenizer()方法从没有空格换行制表符的单词或句子的字符串中提取标记。

示例 #1:
在这个例子中,我们可以看到通过使用tokenize.WhitespaceTokenizer()方法,我们能够从单词流中提取标记。

# import WhitespaceTokenizer() method from nltk
from nltk.tokenize import WhitespaceTokenizer
     
# Create a reference variable for Class WhitespaceTokenizer
tk = WhitespaceTokenizer()
     
# Create a string input
gfg = "GeeksforGeeks \nis\t for geeks"
     
# Use tokenize method
geek = tk.tokenize(gfg)
     
print(geek)

输出 :

示例 #2:

# import WhitespaceTokenizer() method from nltk
from nltk.tokenize import WhitespaceTokenizer
     
# Create a reference variable for Class WhitespaceTokenizer
tk = WhitespaceTokenizer()
     
# Create a string input
gfg = "The price\t of burger \nin BurgerKing is Rs.36.\n"
     
# Use tokenize method
geek = tk.tokenize(gfg)
     
print(geek)

输出 :