借助nltk.tokenize.SpaceTokenizer()
方法,我们可以使用以下方法根据单词之间的空间从字符串中提取标记tokenize.SpaceTokenizer()
方法。
用法:tokenize.SpaceTokenizer()
返回:Return the tokens of words.
范例1:
在这个例子中,我们可以通过使用tokenize.SpaceTokenizer()
方法,我们能够从流中提取标记到单词之间有空格的单词。
# import SpaceTokenizer() method from nltk
from nltk.tokenize import SpaceTokenizer
# Create a reference variable for Class SpaceTokenizer
tk = SpaceTokenizer()
# Create a string input
gfg = "Geeksfor Geeks.. .$$&* \nis\t for geeks"
# Use tokenize method
geek = tk.tokenize(gfg)
print(geek)
输出:
[‘Geeksfor’, ‘Geeks..’, ‘.$$&*’, ‘\nis\t’, ‘for’, ‘geeks’]
范例2:
# import SpaceTokenizer() method from nltk
from nltk.tokenize import SpaceTokenizer
# Create a reference variable for Class SpaceTokenizer
tk = SpaceTokenizer()
# 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)
输出:
[‘The’, ‘price\t’, ‘of’, ‘burger’, ‘\nin’, ‘BurgerKing’, ‘is’, ‘Rs.36.\n’]
相关用法
- Python nltk.tokenize.SExprTokenizer()用法及代码示例
- Python nltk.tokenize.LineTokenizer用法及代码示例
- Python NLTK nltk.tokenize.ConditionalFreqDist()用法及代码示例
- Python nltk.tokenize.TabTokenizer()用法及代码示例
- Python nltk.tokenize.StanfordTokenizer()用法及代码示例
- Python nltk.tokenizer.word_tokenize()用法及代码示例
- Python nltk.tokenize.mwe()用法及代码示例
- Python nltk.WhitespaceTokenizer用法及代码示例
- Python nltk.TweetTokenizer()用法及代码示例
- Python NLTK tokenize.regexp()用法及代码示例
- Python NLTK tokenize.WordPunctTokenizer()用法及代码示例
注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python NLTK | nltk.tokenize.SpaceTokenizer()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。