【发布时间】:2011-07-10 00:11:51
【问题描述】:
我要做的是将文本拆分为他的最终元素。
例如:
from nltk.tokenize import *
txt = "A sample sentences with digits like 2.119,99 or 2,99 are awesome."
regexp_tokenize(txt, pattern='(?:(?!\d)\w)+|\S+')
['A','sample','sentences','with','digits','like','2.199,99','or','2,99','are','awesome','.']
您可以看到它运行良好。我的问题是:如果数字在文本的末尾会发生什么?
txt = "Today it's 07.May 2011. Or 2.999."
regexp_tokenize(txt, pattern='(?:(?!\d)\w)+|\S+')
['Today', 'it', "'s", '07.May', '2011.', 'Or', '2.999.']
结果应该是: ['Today', 'it', "'s", '07.May', '2011','.', 'Or', '2.999','.']
我必须做什么才能得到上面的结果?
【问题讨论】:
-
不要
import *。不好的做法。
标签: python regex nltk tokenize