若要按照自己的规则进行分词,使用正则分词器:RegexpTokenizer
from nltk.tokenize import RegexpTokenizer
sentence = """Thomas Jefferson began building Monticello at the age of 26."""
# 按照自己的规则进行分词,使用正则分词器
# \w 匹配字母、数字、下划线
# 匹配任何非空白字符
tokenizer = RegexpTokenizer(r'\w+|$[0-9.]+|\S+')
print(tokenizer.tokenize(sentence))