From 284bd38336427ce57686140f7631f5fa3634e8f5 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 12 Dec 2022 17:06:07 +0800 Subject: [PATCH] feat: demo of chinese check --- src/character/chinese.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 src/character/chinese.py diff --git a/src/character/chinese.py b/src/character/chinese.py new file mode 100755 index 0000000..b56f1ae --- /dev/null +++ b/src/character/chinese.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +def is_traditional(character: str) -> bool: # whether character is traditional chinese + character = character[0] + try: + character.encode('big5hkscs') + except: + return False + return True + + +def is_simplified(character: str) -> bool: # whether character is simplified chinese + character = character[0] + try: + character.encode('gb2312') + except: + return False + return True + + +def chinese_check(character: str) -> None: + character = character[0] + print(character) + print('is_simplified ->', is_simplified(character)) + print('is_traditional ->', is_traditional(character)) + print() + + +chinese_check('我') +chinese_check('飯') +chinese_check('们')