借助nltk.tokenize.StanfordTokenizer()
方法,我們可以使用以下方法從字符串或數字字符串中提取標記tokenize.StanfordTokenizer()
方法。它遵循斯坦福標準生成令牌。
用法:tokenize.StanfordTokenizer()
返回: Return the tokens from a string of characters or numbers.
範例1:
在這個例子中,我們可以通過使用tokenize.SExprTokenizer()
方法,我們能夠使用斯坦福標準從字符或數字流中提取令牌。
# import StanfordTokenizer() method from nltk
from nltk.tokenize.stanford import StanfordTokenizer
# Create a reference variable for Class StanfordTokenizer
tk = StanfordTokenizer()
# Create a string input
gfg = "Geeks f o r Geeks"
# Use tokenize method
geek = tk.tokenize(gfg)
print(geek)
輸出:
[‘Geeks’, ‘f’, ‘o’, ‘r’, ‘Geeks’]
範例2:
# import StanfordTokenizer() method from nltk
from nltk.tokenize.stanford import StanfordTokenizer
# Create a reference variable for Class StanfordTokenizer
tk = StanfordTokenizer()
# Create a string input
gfg = "This is your great author."
# Use tokenize method
geek = tk.tokenize(gfg)
print(geek)
輸出:
[‘This’, ‘is’, ‘your’, ‘great’, ‘author’, ‘.’]
相關用法
- Python nltk.tokenizer.word_tokenize()用法及代碼示例
- Python NLTK nltk.tokenize.ConditionalFreqDist()用法及代碼示例
- Python nltk.tokenize.LineTokenizer用法及代碼示例
- Python nltk.tokenize.SExprTokenizer()用法及代碼示例
- Python nltk.tokenize.TabTokenizer()用法及代碼示例
- Python nltk.tokenize.SpaceTokenizer()用法及代碼示例
- Python nltk.WhitespaceTokenizer用法及代碼示例
- Python nltk.TweetTokenizer()用法及代碼示例
- Python nltk.tokenize.mwe()用法及代碼示例
- Python NLTK tokenize.regexp()用法及代碼示例
- Python NLTK tokenize.WordPunctTokenizer()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python NLTK | nltk.tokenize.StanfordTokenizer()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。