Python NLTK | nltk.tokenizer.word_tokenize()
在nltk.tokenize.word_tokenize()
方法的帮助下,我们可以使用tokenize.word_tokenize()
方法从字符串字符提取标记。它实际上返回单个单词的音节。一个单词可以包含一个或两个音节。
Syntax : tokenize.word_tokenize()
Return : Return the list of syllables of words.
示例 #1:
在这个例子中,我们可以看到通过使用tokenize.word_tokenize()
方法,我们能够从单词或句子流中提取音节。
# import SyllableTokenizer() method from nltk
from nltk import word_tokenize
# Create a reference variable for Class word_tokenize
tk = SyllableTokenizer()
# Create a string input
gfg = "Antidisestablishmentarianism"
# Use tokenize method
geek = tk.tokenize(gfg)
print(geek)
输出 :
[‘An’, ‘ti’, ‘dis’, ‘es’, ‘ta’, ‘blish’, ‘men’, ‘ta’, ‘ria’, ‘nism’]
示例 #2:
# import SyllableTokenizer() method from nltk
from nltk.tokenize import word_tokenize
# Create a reference variable for Class word_tokenize
tk = SyllableTokenizer()
# Create a string input
gfg = "Gametophyte"
# Use tokenize method
geek = tk.tokenize(gfg)
print(geek)
输出 :
[‘Ga’, ‘me’, ‘to’, ‘phy’, ‘te’]