嗯,两个分词器的工作方式几乎相同,将给定的句子拆分为单词。但你可以想到TweetTokenizer
作为一个子集word_tokenize
. TweetTokenizer
保持主题标签完整,同时word_tokenize
没有。
我希望下面的例子能够消除您所有的疑虑......
from nltk.tokenize import TweetTokenizer
from nltk.tokenize import word_tokenize
tt = TweetTokenizer()
tweet = "This is a cooool #dummysmiley: :-) :-P <3 and some arrows < > -> <-- @remy: This is waaaaayyyy too much for you!!!!!!"
print(tt.tokenize(tweet))
print(word_tokenize(tweet))
# output
# ['This', 'is', 'a', 'cooool', '#dummysmiley', ':', ':-)', ':-P', '<3', 'and', 'some', 'arrows', '<', '>', '->', '<--', '@remy', ':', 'This', 'is', 'waaaaayyyy', 'too', 'much', 'for', 'you', '!', '!', '!']
# ['This', 'is', 'a', 'cooool', '#', 'dummysmiley', ':', ':', '-', ')', ':', '-P', '<', '3', 'and', 'some', 'arrows', '<', '>', '-', '>', '<', '--', '@', 'remy', ':', 'This', 'is', 'waaaaayyyy', 'too', 'much', 'for', 'you', '!', '!', '!', '!', '!', '!']
你可以看到word_tokenize
已经分裂#dummysmiley
as '#'
and 'dummysmiley'
,而 TweetTokenizer 没有,因为'#dummysmiley'
. TweetTokenizer
主要是为了分析推文而构建的。
您可以从中了解有关分词器的更多信息link https://chendianblog.wordpress.com/2016/11/25/different-types-of-tokenizers-in-nltk/