首页 > 编程语言 > 详细

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

时间:2015-10-23 13:17:42      阅读:145      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!