借助NLTK nltk.tokenize.mwe()
方法,我們可以將音頻流令牌化為multi_word表達令牌,該令牌有助於通過使用下劃線將令牌與下劃線綁定nltk.tokenize.mwe()
方法。請記住,它區分大小寫。
用法:MWETokenizer.tokenize()
返回: Return bind tokens as one if declared before.
範例1:
在這個例子中,我們使用MWETokenizer.tokenize()
方法,該方法用於綁定之前定義的令牌。我們還可以通過使用添加預定義的令牌tokenizer.add_mwe()
方法。
# import MWETokenizer() method from nltk
from nltk.tokenize import MWETokenizer
# Create a reference variable for Class MWETokenizer
tk = MWETokenizer([('g', 'f', 'g'), ('geeks', 'for', 'geeks')])
# Create a string input
gfg = "geeks for geeks g f g"
# Use tokenize method
geek = tk.tokenize(gfg.split())
print(geek)
輸出:
[‘geeks_for_geeks’, ‘g_f_g’]
範例2:
# import MWETokenizer() method from nltk
from nltk.tokenize import MWETokenizer
# Create a reference variable for Class MWETokenizer
tk = MWETokenizer([('g', 'f', 'g'), ('geeks', 'for', 'geeks')])
tk.add_mwe(('who', 'are', 'you'))
# Create a string input
gfg = "who are you at geeks for geeks"
# Use tokenize method
geek = tk.tokenize(gfg.split())
print(geek)
輸出:
[‘who_are_you’, ‘at’, ‘geeks_for_geeks’]
相關用法
- Python nltk.tokenize.SExprTokenizer()用法及代碼示例
- Python nltk.tokenize.LineTokenizer用法及代碼示例
- Python NLTK nltk.tokenize.ConditionalFreqDist()用法及代碼示例
- Python nltk.tokenize.SpaceTokenizer()用法及代碼示例
- Python nltk.tokenize.TabTokenizer()用法及代碼示例
- Python nltk.tokenize.StanfordTokenizer()用法及代碼示例
- Python nltk.tokenizer.word_tokenize()用法及代碼示例
- Python nltk.WhitespaceTokenizer用法及代碼示例
- Python nltk.TweetTokenizer()用法及代碼示例
- Python NLTK tokenize.regexp()用法及代碼示例
- Python NLTK tokenize.WordPunctTokenizer()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python NLTK | nltk.tokenize.mwe()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。