Python来识别字符串所属语言类型(langid 、langdetect)

目前有两个开源项目: langid 和 langdetect

pip install langdetect

项目地址:https://github.com/Mimino666/langdetect

但是使用langdetect来判断中文时候就会爆出错误

# -*- coding:utf-8 -*-

from langdetect import detect

str = '你好'

print detect(str)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

但是使用判断英文时候就是正常的,这个时候用来做字符串检测不太好使了。

pip install langid

项目地址:https://github.com/saffsd/langid.py

使用另一个项目langid 来做检测还算正常,

import langid

s1 = "你好"

array = langid.classify(s1)

print array[0]

文章地址:https://www.apizl.com/archives/view-148728-1.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值