利用Python将文本中的中英文分离方法
在进行文本分析、提取关键词时,新闻评论等文本通常是中英文及其他语言的混杂,若不加处理直接分析,结果往往差强人意。
下面对中英文文本进行分离做一下总结:
1、超短文本,ASCII识别。
s="China'sLegendHoldingswillsplititsseveralbusinessarmstogopubliconstockmarkets,thegroup'spresidentZhuLinansaidonTuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。" result="".join(iforiinsiford(i)<256) print(result)
out: China'sLegendHoldingswillsplititsseveralbusinessarmstogopubliconstockmarkets,thegroup'spresidentZhuLinansaidonTuesday.
2、unicode编码识别
importre s="China'sLegendHoldingswillsplititsseveralbusinessarmstogopubliconstockmarkets,thegroup'spresidentZhuLinansaidonTuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。" uncn=re.compile(r'[\u0061-\u007a,\u0020]') en="".join(uncn.findall(s.lower())) print(en)
out: chinaslegendholdingswillsplititsseveralbusinessarmstogopubliconstockmarkets,thegroupspresidentzhulinansaidontuesday
中文的编码范围是:\u4e00-\u9fa5,相应的[^\u4e00-\u9fa5]可匹配非中文。
匹配英文时,需要将空格[\u0020]加入,不然单词之间没空格了。
以上这篇利用Python将文本中的中英文分离方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 步入高中祝福语简短励志
11 朋友药店开业祝福语简短
12 祝朋友祝福语简短好看
13 毕业祝福语简短英语小学
14 预祝高尔夫的祝福语简短
15 小清新的祝福语简短
16 朋友搬迁新房祝福语简短
17 新年的祝福语简短的
18 恭喜订婚的祝福语简短