我正在尝试将句子分解为单词。通常我会使用
我考虑过这样做:
但这种方法感觉有点不正规。有没有更好的方法来做到这一点?
textstring.split(' ')
,但我还想将逗号和句号分开,例如"No, thank you"应该被分成["No", ",", "thank", "you"]
而不是["No,", "thank", "you"]
。我考虑过这样做:
textstring.replace(",", " ,").replace(".", " .").split(' ')
但这种方法感觉有点不正规。有没有更好的方法来做到这一点?
nltk
吗? - jonrsharpe