美文网首页
NLP 文本预处理utils

NLP 文本预处理utils

作者: lzhenboy | 来源:发表于2020-09-22 15:05 被阅读0次

1、中文标点

zh_punc = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."

2、strip() 的正则表达式版本

def re_strip(text, param=' '):
    pattern = re.compile(r'^([' + str(param) + r']*)(.*?)([' + str(param) + ']*)$')
    rst = pattern.search(text)
    return rst.group(2) if result else None

示例:
去除字符串首尾的中文标点

text = ';我爱中国'
cleaned_text = re_strip(text, zh_punc)
print(cleaned_text)

`cleaned text:  我爱中国`

参考文献

https://blog.csdn.net/dongyu1703/article/details/81782081

相关文章

网友评论

      本文标题:NLP 文本预处理utils

      本文链接:https://www.haomeiwen.com/subject/goywyktx.html