如何检测文字的语言? [英] How to detect language of text?

查看:214
本文介绍了如何检测文字的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许用户输入文本片段的表格.那么如何弄清楚输入文字的语言呢?

I have a form which lets users input text snippets. So how can figure out the language of the entered text?

现在特别是这些语言:

阿拉伯语:هذههيبعضالنصوصالعربية

Arabic: هذه هي بعض النصوص العربية

中文:这是一些阿拉伯文字

Chinese: 这是一些阿拉伯文字

日语:これは,いくつかのアラビア语のテキストです

Japanese: これは、いくつかのアラビア語のテキストです

检测也适用于通过API检索的文本(不涉及浏览器)

The detection has work on text which is retrieved via an API too (no browser involved)

推荐答案

您可以确定字符是否来自Unicode映射的阿拉伯语,中文或日语部分.

You can figure out whether the characters are from the Arabic, Chinese, or Japanese sections of the Unicode map.

如果您查看维基百科上的列表,则会看到每种语言在地图上有很多部分.但是您不需要翻译,因此您不必担心每一个字形.

If you look at the list on Wikipedia, you'll see that each of those languages has many sections of the map. But you're not doing translation, so you don't need to worry about every last glyph.

例如,您的中文文本开始(以十六进制表示)0x8FD9 0x662F 0x4E00-这些全部在中文的"CJK统一表意文字"部分中.以下是一些入门指南:

For example, your Chinese text begins (in hex) 0x8FD9 0x662F 0x4E00 - and those are all in the "CJK Unified Ideographs" section, which is Chinese. Here are a few ranges to get you started:

阿拉伯语(0600–06FF)

Arabic (0600–06FF)

日语

  • 平假名(3040–309F)
  • 片假名(30A0–30FF)
  • 看板(3190–319F)

中文

  • 中日韩统一表意文字(4E00–9FFF)

((通过使用中文到Unicode转换器,我得到了您的中文的十六进制.)

这篇关于如何检测文字的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆