from langdetect import detectfrom langdetect import detect_langs
s1 = "本篇博客主要介绍两款语⾔探测⼯具,⽤于区分⽂本到底是什么语⾔,"s2 = 'We are pleased to introduce today a new technology'p
rint(detect(s1))
print(detect(s2))
print(detect_langs(s3)) # detect_langs()输出探测出的所有语⾔类型及其所占的⽐例
输出结果如下:注:语⾔类型主要参考的是ISO 639-1语⾔编码标准,详⻅ISO 639-1百度百科
跟上⼀个语⾔检测⽐较,准确率低,效率⾼。
4. phone 中国⼿机归属地查询:
repo: ls0f/phone
已集成到 python package cocoNLP中
from phone import Phone
p = Phone()
p.find(18100065143)#return {'phone': '18100065143', 'province': '上海', 'city': '上海', 'zip_code': '200000', 'area_code': '021', 'phone_type':
'电信'}
⽀持号段: 13,15,18*,14[5,7],17[0,6,7,8]
记录条数: 360569 (updated:2017年4⽉)
作者提供了数据phone.dat ⽅便⾮python⽤⼾Load数据。
5. phone国际⼿机、电话归属地查询:
repo: AfterShip/phone
npm install phone
import phone from 'phone';
phone('+852 6569-8900'); // return ['+85265698900', 'HKG']
phone('(817) 569-8900'); // return ['+18175698900, 'USA']
6. ngender 根据名字判断性别:
repo: observerss/ngender
基于朴素⻉叶斯计算的概率
pip install ngender
>>> import ngender>>> ngender.guess('赵本⼭')
('male', 0.9836229687547046)>>> ngender.guess('宋丹丹')
('female', 0.9759486128949907)
7. 抽取email的正则表达式
已集成到 python package cocoNLP中
email_pattern = '^[*#\u4e00-\u9fa5 a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$'emails = re.findall(email_pattern, t
ext, flags=0)