【发布时间】:2019-08-18 00:41:43
【问题描述】:
我正在拆分文本 para 并使用以下内容保留换行符 \n
from nltk import SpaceTokenizer
para="\n[STUFF]\n comma, with period. the new question? \n\nthe\n \nline\n new char*"
sent=SpaceTokenizer().tokenize(para)
这给了我以下信息
print(sent)
['\n[STUFF]\n', '', 'comma,', '', 'with', 'period.', 'the', 'new', 'question?', '\n\nthe\n', '', '\nline\n', 'new', 'char*']
我的目标是得到以下输出
['\n[STUFF]\n', '', 'comma', ',', '', 'with', 'period', '.', 'the', 'new', 'question', '?', '\n\nthe\n', '', '\nline\n', 'new', 'char*']
也就是说,我想将'comma,'拆分成'comma',',' 拆分将'period.'拆分成'period',@ 987654332@ 拆分 'question?' 成 'question', '?' while 保留\n
我试过word_tokenize,它会实现拆分'comma'、','等但不保留\n
如何在保留\n 的同时进一步拆分sent,如上所示?
【问题讨论】:
标签: python string split nltk tokenize