Testing for Japanese/Chinese Characters in a string

后端 未结 6 620
我在风中等你
我在风中等你 2020-12-18 04:47

I have a program that reads a bunch of text and analyzes it. The text may be in any language, but I need to test for japanese and chinese specifically to analyze them a diff

6条回答
  •  情书的邮戳
    2020-12-18 05:14

    You won't be able to test a single character to tell with certainty that it is Japanese or Chinese because of the way the unihan code points are implemented in the Unicode standard. Basically, every Chinese character is a potential Japanese character. However, the reverse is not true. Also, there are a number of conventions that could be used to test to see if a block of text is in one language or the other.

    1. Simplifications - if the character you are testing is a PRC simplification such as 门 is only available in main land Chinese.
    2. Kana - if the character is one of the many Japanese kana characters such as あいうえお then the text block you are working with is definitely Japanese.

    The problem arises with the sheer number of characters and words that are in common. However, if I needed a quick and dirty solution to this problem, I would check my entire blocks of text for kana - if the text contains kana then I know it is Japanese. If you need to distinguish Korean as well, I would test for Hangul. Also, if you need to distinguish what type of Chinese, testing for types of simplifications would be the best approach.

提交回复
热议问题