使用Regex进行句子分割 [英] Sentence segmentation using Regex

查看:104
本文介绍了使用Regex进行句子分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本(SMS)消息很少,我想使用period('.')作为分隔符对它们进行分段.我无法处理以下类型的消息.如何在Python中使用Regex分割这些消息.

I have few text(SMS) messages and I want to segment them using period('.') as a delimiter. I am unable to handle following types of messages. How can I segment these messages using Regex in Python.

细分之前:


'hyper count 16.8mmol/l.plz review b4 5pm.just to inform u.thank u'
'no of beds 8.please inform person in-charge.tq'

细分后:


'hyper count 16.8mmol/l' 'plz review b4 5pm' 'just to inform u' 'thank u'
'no of beds 8' 'please inform person in-charge' 'tq'

每行都是单独的消息

已更新:

我正在进行自然语言处理,因此可以将'16.8mmmol/l''no of beds 8.2 cups of tea.'视为相同. 80%的精度对我来说足够了,但我想尽可能减少False Positive.

I am doing natural language processing and I feel its okay to treat '16.8mmmol/l' and 'no of beds 8.2 cups of tea.' as same. 80% accuracy is enough for me but I want to reduce False Positive as much as possible.

推荐答案

re.split('(?<!\d)\.|\.(?!\d)', 'hyper count 16.8mmol/l.plz review b4 5pm.just to inform u.thank u')

环顾四周可确保一侧或另一侧都不是数字.因此,这也涵盖了16.8情况.如果两边都有数字,则该表达式不会拆分.

The lookarounds ensure that either on one or the other side is not a digit. So this covers also the 16.8 case. This expression will not split if there are on both sides digits.

这篇关于使用Regex进行句子分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆