有趣的Python項目GitHub分享!收藏貼,強烈建議

涉及內容包括:中英文敏感詞、語言檢測、中外手機/電話歸屬地/運營商查詢、名字推斷性別、手機號抽取、身份證抽取、郵箱抽取、中日文人名庫、中文縮寫庫、拆字詞典、詞彙情感值、停用詞、反動詞表、暴恐詞表、繁簡體轉換、英文模擬中文發音、汪峰歌詞生成器、職業名稱詞庫、同義詞庫、反義詞庫、否定詞庫、汽車品牌詞庫、汽車零件詞庫、連續英文切割、各種中文詞向量、公司名字大全、古詩詞庫、IT詞庫、財經詞庫、成語詞庫、地名詞庫、歷史名人詞庫、詩詞詞庫、醫學詞庫、飲食詞庫、法律詞庫、汽車詞庫、動物詞庫、中文聊天語料

1. textfilter: 中英文敏感詞過濾

項目地址:

https://github.com/observerss/textfilter
 >>> f = DFAFilter()
>>> f.add("sexy")
>>> f.filter("hello sexy baby")
hello **** baby

敏感詞包括政治、髒話等話題詞彙。其原理主要是基於詞典的查找(項目中的keyword文件),內容很勁爆。。。

2. langid:97種語言檢測

項目地址:

https://github.com/saffsd/langid.py

pip install langid

>>> import langid
>>> langid.classify("This is a test")
('en', -54.41310358047485)

3. langdetect:另一個語言檢測

項目地址:

https://code.google.com/archive/p/language-detection/ 

pip install langdetect

from langdetect import detect
from langdetect import detect_langs
s1 = "本篇博客主要介紹兩款語言探測工具,用於區分文本到底是什麼語言,"
s2 = 'We are pleased to introduce today a new technology'
print(detect(s1))
print(detect(s2))
print(detect_langs(s3)) # detect_langs()輸出探測出的所有語言類型及其所佔的比例

輸出結果如下: 注:語言類型主要參考的是ISO 639-1語言編碼標準,詳見ISO 639-1百度百科

跟上一個語言檢測比較,準確率低,效率高。

4. phone 中國手機歸屬地查詢:

項目地址:

https://github.com/ls0f/phone
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國際手機、電話歸屬地查詢:

項目地址:

https://github.com/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 根據名字判斷性別:observerss/ngender

項目地址:

https://github.com/observerss/ngender

pip install ngender # 基於樸素貝葉斯計算的概率

>>> import ngender
>>> ngender.guess('趙本山')
('male', 0.9836229687547046)
>>> ngender.guess('宋丹丹')
('female', 0.9759486128949907)

7. 抽取email的正則表達式

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, text, flags=0)

8. 抽取phone_number的正則表達式

cellphone_pattern = '^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$'
phoneNumbers = re.findall(cellphone_pattern, text, flags=0)

9. 抽取身份證號的正則表達式

IDCards_pattern = r'^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$'
IDs = re.findall(IDCards_pattern, text, flags=0)

10. 人名語料庫: wainshine/Chinese-Names-Corpus

項目地址:

https://github.com/wainshine/Chinese-Names-Corpus
中文(現代、古代)名字、日文名字、中文的姓和名、稱呼(大姨媽、小姨媽等)、英文->中文名字(李約翰)、成語詞典

(可用於中文分詞、姓名識別)

11. 中文縮寫庫:

項目地址:

https://github.com/zhangyics/Chinese-abbreviation-dataset
全國人大: 全國/n 人民/n 代表大會/n 

中國: 中華人民共和國/ns
女網賽: 女子/n 網球/n 比賽/vn

12. 漢語拆字詞典:

項目地址:

https://github.com/kfcd/chaizi
漢字	拆法 (一)	拆法 (二)	拆法 (三)
拆 手 斥 扌 斥 才 斥

13. 詞彙情感值:rainarch/SentiBridge

項目地址:

https://github.com/rainarch/SentiBridge
山泉水	充沛	0.400704566541	0.370067395878
視野 寬廣 0.305762728932 0.325320747491
大峽谷 驚險 0.312137906517 0.378594957281

14. 中文詞庫、停用詞、敏感詞 dongxiexidian/Chinese

項目地址:

https://github.com/dongxiexidian/Chinese

此package的敏感詞庫分類更細:

反動詞庫, 敏感詞庫表統計, 暴恐詞庫, 民生詞庫, 色情詞庫

15. 漢字轉拼音:mozillazg/python-pinyin

項目地址:

https://github.com/mozillazg/python-pinyin

文本糾錯會用到

16. 中文繁簡體互轉:skydark/nstools

項目地址:

https://github.com/skydark/nstools

17. 英文模擬中文發音引擎 funny chinese text to speech enginee:

項目地址:

https://github.com/tinyfool/ChineseWithEnglish
say wo i ni
#說:我愛你

相當於用英文音標,模擬中文發音。

18. 汪峰歌詞生成器:

項目地址:

https://github.com/phunterlau/wangfeng-rnn
我在這裡中的夜裡
就像一場是一種生命的意旪
就像我的生活變得在我一樣
可我們這是一個知道
我只是一天你會怎嗎

19. 同義詞庫、反義詞庫、否定詞庫:

項目地址:

https://github.com/phunterlau/wangfeng-rnn

20. 無空格英文串分割、抽取單詞:wordinja

項目地址:

https://github.com/kfcd/chaizi
>>> import wordninja
>>> wordninja.split('derekanderson')
['derek', 'anderson']
>>> wordninja.split('imateapot')
['im', 'a', 'teapot']

21. IP地址正則表達式:

(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)

22. 騰訊QQ號正則表達式:

[1-9]([0-9]{5,11})

23. 國內固話號碼正則表達式:

[0-9-()()]{7,18}

24. 用戶名正則表達式:

[A-Za-z0-9_\-\\u4e00-\\u9fa5]+

25. 汽車品牌、汽車零件相關詞彙:

項目地址:
https://github.com/fighting41love/funNLP/tree/master/data

26. 時間抽取:

在2016年6月7日9:44執行測試,結果如下
Hi,all。下週一下午三點開會
>> 2016-06-13 15:00:00-false
週一開會

>> 2016-06-13 00:00:00-true
下下週一開會
>> 2016-06-20 00:00:00-true

java version

python version

27. 連續英文切割:

項目地址:

https://github.com/keredson/wordninja

可用於網址中的英文單詞切割等任務

>>> import wordninja
>>> wordninja.split('derekanderson')
['derek', 'anderson']
>>> wordninja.split('imateapot')
['im', 'a', 'teapot']
>>> wordninja.split('heshotwhointhewhatnow')
['he', 'shot', 'who', 'in', 'the', 'what', 'now']

28. 各種中文詞向量:

項目地址:

https://github.com/Embedding/Chinese-Word-Vectors

29. 公司名字大全:

項目地址:

https://github.com/wainshine/Company-Names-Corpus 

30. 古詩詞庫:

項目地址:

https://github.com/panhaiqi/AncientPoetry

31. 中文聊天語料

項目地址:

https://github.com/codemayq/chaotbot_corpus_Chinese

該庫蒐集了包含:豆瓣多輪, PTT八卦語料, 青雲語料, 電視劇對白語料, 貼吧論壇回帖語料,微博語料,小黃雞語料


分享到:


相關文章: