我有以下字符串:
title = 'Tesla S&P Debut Comes All at Once'
当我在NLTK中对此标记化时,我得到以下信息:
token = nltk.word_tokenize(title1)
token
['Tesla', 'S', '&', 'P', 'Debut', 'Comes', 'All', 'at', 'Once']
令牌化的S&P
原因是&
。
如何防止NLTK分割成特殊的特殊字符?
您可以在nltk中使用regexp_tokenize,在其中可以选择正则表达式来定义seps
from nltk import regexp_tokenize
title = 'Tesla S&P Debut Comes All at Once'
tokens = regexp_tokenize(title, pattern=r"\s|[\.,;']", gaps=True)
print(tokens)
[“特斯拉”,“标准普尔”,“首次亮相”,“来临”,“全部”,“在”,“一次”]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句