目前有两个开源项目: 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
本文对比了两个语言检测开源项目langid和langdetect。在使用langdetect进行中文检测时出现错误,而langid则能正常工作。文章提供了安装与使用这两个项目的详细步骤。
1223

被折叠的 条评论
为什么被折叠?



