📜  Python NLTK | nltk.tokenizer.word_tokenize()

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

Python NLTK | nltk.tokenizer.word_tokenize()

nltk.tokenize.word_tokenize()方法的帮助下,我们可以使用tokenize.word_tokenize()方法从字符串字符提取标记。它实际上返回单个单词的音节。一个单词可以包含一个或两个音节。

示例 #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)

输出 :

示例 #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)

输出 :