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')
python处理杂乱无章的文本
于 2023-05-02 18:16:09 首次发布