当前位置: 移动技术网 > IT编程>脚本编程>Python > Python语言检测模块langid和langdetect的使用实例

Python语言检测模块langid和langdetect的使用实例

2019年03月20日  | 移动技术网IT编程  | 我要评论

ngacn.cc,韩冬辉,东营交友网

之前使用数据编码风格检测的模块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.")

结果如下:

('en', 9.061840057373047)
('it', -35.41771221160889)
('zh', -85.79573845863342)
('en', 0.16946150595865334)
zh-cn
en
[en:0.999998109575]
[pl:0.571426592237, fi:0.428568772028]

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网