Skip to main content
 首页 » 编程设计

python之如何使用 python 将文本拆分为子句

2025年05月04日13findumars

我想将文本拆分为子句。我该怎么做?

例如:

text = "Hi, this is an apple. Hi, that is pineapple." 

结果应该是:

['Hi,', 
 'this is an apple.', 
 'Hi,', 
 'that is pineapple.'] 

(附:我尝试使用 string.split(r'[,.]'),但它会删除分隔符。)

请您参考如下方法:

也许这也行:

text.replace(', ', ',, ').replace('. ', '., ').split(', ') 

结果:

['Hi,', 'this is an apple.', 'Hi,', 'that is pineapple.']