python处理杂乱无章的文本

def post_text(text,save_name):
    '''实现将杂乱文本规整为整齐的句子'''
    text = text.replace('\n', '我是风流倜傥的帅哥哥哥哥')#先把杂乱句子的换行符换成任意字段
    text=text.replace('我是风流倜傥的帅哥哥哥哥', ' ')
    print(text)
    sentences = []
    s = ""
    for i in range(len(text)):
        if text[i] == "." and (i == len(text) - 1 or not text[i+1].isdigit()):
            if s:
                sentences.append(s.strip())
                s = ""
        else:
            s += text[i]
    if s:
        sentences.append(s.strip())
    for i in range(len(sentences)):#去除空行
        if sentences[i]=='':
            sentences.remove(sentences[i])
    for i in range(0,len(sentences)):
        print('----------------------',sentences[i])
    with open(".\word\\{save_name}.txt".format(save_name=save_name), "w", encoding="utf-8") as f:
        for a in sentences:
            f.write(a+'.\n')
    print(sentences)
    return (sentences)
text = '''NOTE:
No FPI or dimensional checks required for except as noted.
(1)
Visually check the part as follows:
(a)
Visually check the inner and outer platforms of vane segments for cracks, refer
to Figure 5011-3844760. Cracks are not permitted.
(b)
Visually check the LE of vanes for cracks. Cracks are not permitted.
(c)
Visually check the trailing edge for cracks. Cracks are not permitted.
(d)
Visually check nozzle segment vanes leading/trailing edges for buckling and
missing pieces, refer to Figure 5011-3844760.
1
Buckling of 0.050 inch (1.27 mm) maximum from nominal contour is
permitted.
'''
#post_text(text,'a')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值