语言检测

比较 langid 和 langdetect

python2.7

import langid
langid.classify("This is a test")
('en', -54.41310358047485)
langid.classify("你好 世界")
('zh', -74.89392423629761)
langid.classify("(")
('en', 9.061840057373047)
langid.classify("(")
('ja', -0.8925070762634277)
langid.classify("中鼎集團有限公司")
('zh', -77.54190039634705)

from langdetect import detect
detect("Hello World")
'en'

detect("CTCI(中鼎集團有限公司)")

报错,编码问题

detect(u"CTCI(中鼎集團有限公司)")
'ko'

总体觉得 langid 更合适。

猜你喜欢

转载自www.cnblogs.com/bingwork/p/9429647.html