码迷,mamicode.com
首页 > 编程语言 > 详细

python 参议院文本预处理的一维数组的间隔空间

时间:2015-10-23 13:17:59      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/python
import re
def pre_process_msg ( msgIn ):
    if msgIn=="":
        return "msgIn_Input_Error,should‘nt Null, it is Strings"
    else:
         #1 trim
         msg = msgIn
         msg = msg.strip()
         #2 process msg internal special char replace with “ ”
         dst_replace_pattern1 = re.compile(‘\n‘)
         msg = dst_replace_pattern1.sub(" ",msg)
         dst_replace_pattern1 = re.compile(‘\r‘)
         msg = dst_replace_pattern1.sub(" ",msg)
         dst_replace_pattern1 = re.compile(‘\t‘)
         msg = dst_replace_pattern1.sub(" ",msg)
         #3 one or more space replaced with one space,to form srings with " " internal
         result=""
         result=re.sub(" {1,}", " ", msg)
         msg=result.strip()
         print "‘"+msg+"‘"
         return msg

版权声明:本文博主原创文章,博客,未经同意不得转载。

python 参议院文本预处理的一维数组的间隔空间

标签:

原文地址:http://www.cnblogs.com/hrhguanli/p/4904190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!