首页 > 编程语言 >python 实现多语种检测

python 实现多语种检测

时间:2023-03-11 14:23:23浏览次数:38  
标签:detect zh cn 多语种 python 检测 txt

首先安装如下包:

pip install langdetect

然后新建一个 python 文件,重命名为 detect.py,粘贴进如下案例代码:

from langdetect import *

DetectorFactory.seed = 0

txt = "你好,世界!" # 要检测的文本

print(detect(txt)) # 打印检测出的语种语言码
print(detect_langs(txt)) # 打印检测语种的置信概率

运行该代码:

python detect.py

查看输出结果:

zh-cn
[zh-cn:0.9999922534631368]

 语言码与语种名对应关系见下表:

全球语言代码(ISO 639-1)

目前该包支持如下 55 种语言:

af, ar, bg, bn, ca, cs, cy, da, de, el, en, es, et, fa, fi, fr, gu, he, hi, hr, hu, id, it, ja, kn, ko, lt, lv, mk, ml, mr, ne, nl, no, pa, pl, pt, ro, ru, sk, sl, so, sq, sv, sw, ta, te, th, tl, tr, uk, ur, vi, zh-cn, zh-tw

 

标签:detect,zh,cn,多语种,python,检测,txt
From: https://www.cnblogs.com/george-chou/p/17205958.html

相关文章