Python语言检测模块langid和langdetect的使用实例-创新互联
之前使用数据编码风格检测的模块chardet比较多一点,今天提到的两个模块是检测数据的语言类型,比如是:中文还是英文,模块的使用方法也比较简单,我这里只是简单地使用了一下,因为项目中有这个需求,所以拿来用了一下,并没有深入地去研究这两个模块,模块的地址链接我都给出来了,需要的话可以去研究下:

def langidFunc():
'''
https://github.com/yishuihanhan/langid.py
'''
print langid.classify("We Are Family")
print langid.classify("Questa e una prova")
print langid.classify("我们都有一个家")
identifier=LanguageIdentifier.from_modelstring(model,norm_probs=True)
print identifier.classify("We Are Family")
def langdetectFunc():
'''
https://github.com/yishuihanhan/langdetect
'''
s1=u"本篇文章主要介绍两款语言探测工具,用于区分文本到底是什么语言,"
s2=u'We are pleased to introduce today a new technology'
print detect(s1)
print detect(s2)
print detect_langs(s2) # detect_langs()输出探测出的所有语言类型及其所占的比例
print detect_langs("Otec matka syn.")另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站名称:Python语言检测模块langid和langdetect的使用实例-创新互联
本文来源:http://www.jxjierui.cn/article/psgji.html


咨询
建站咨询
