利用Python将文本中的中英文分离方法
作者:微澜同学 时间:2023-01-06 11:55:58
在进行文本分析、提取关键词时,新闻评论等文本通常是中英文及其他语言的混杂,若不加处理直接分析,结果往往差强人意。
下面对中英文文本进行分离做一下总结:
1、超短文本,ASCII识别。
s = "China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。"
result = "".join(i for i in s if ord(i) < 256)
print(result)
out:
China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.
2、unicode编码识别
import re
s = "China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。"
uncn = re.compile(r'[\u0061-\u007a,\u0020]')
en = "".join(uncn.findall(s.lower()))
print(en)
out:
chinas legend holdings will split its several business arms to go public on stock markets, the groups president zhu linan said on tuesday
中文的编码范围是:\u4e00-\u9fa5,相应的[^\u4e00-\u9fa5]可匹配非中文。
匹配英文时,需要将空格[\u0020]加入,不然单词之间没空格了。
来源:https://blog.csdn.net/sinat_36972314/article/details/79746291
标签:Python,中英文,分离
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python使用xlsx和pandas处理Excel表格的操作步骤
2021-05-19 02:30:20
![](https://img.aspxhome.com/file/2023/1/81831_0s.jpg)
javascript getElementByTagName的使用
2024-04-10 14:00:36
Trie树_字典树(字符串排序)简介及实现
2022-02-22 23:18:23
![](https://img.aspxhome.com/file/2023/8/120538_0s.gif)
Django使用redis缓存服务器的实现代码示例
2022-12-15 09:16:28
数据库Mysql性能优化详解
2024-01-16 16:45:47
CSS Hacks
2008-07-20 13:04:00
Windows下MySQL 8.0.29 安装和删除图文教程
2024-01-21 20:18:29
![](https://img.aspxhome.com/file/2023/8/109798_0s.jpg)
通过实例简单了解Python中yield的作用
2023-03-10 11:23:17
Python移动测试开发subprocess模块项目实战
2022-09-06 11:11:19
![](https://img.aspxhome.com/file/2023/8/79508_0s.png)
python执行scp命令拷贝文件及文件夹到远程主机的目录方法
2023-07-10 09:12:19
python实现数通设备tftp备份配置文件示例
2022-12-02 13:59:21
详解python函数的闭包问题(内部函数与外部函数详述)
2023-01-22 20:53:01
详解Python中的四种队列
2021-05-10 01:48:04
![](https://img.aspxhome.com/file/2023/4/124894_0s.png)
Python中的字符串切片(截取字符串)的详解
2023-07-23 20:37:59
![](https://img.aspxhome.com/file/2023/1/60711_0s.png)
Flask模板引擎Jinja2使用实例
2022-01-19 11:58:39
一文带你搞懂Python中的数据容器
2021-05-25 16:09:59
Python运算符优先级详细整理
2021-12-17 06:38:14
![](https://img.aspxhome.com/file/2023/5/135305_0s.png)
如何创建CSS的对象,获取合适的粒度
2010-07-09 13:10:00
![](https://img.aspxhome.com/file/UploadPic/20107/9/02-19s.jpg)
ASP读取Exif信息无组件实现过程
2009-02-09 12:52:00
JS实现数字格式千分位相互转换方法
2023-08-31 08:24:48