Browse Source

feat: traditional chinese convert demo

master
Dnomd343 2 years ago
parent
commit
c64943eb7d
  1. 23
      src/chinese/convert.py

23
src/chinese/convert.py

@ -0,0 +1,23 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from snownlp import SnowNLP
def traditionalCheck(sentence: str) -> None:
simplified = SnowNLP(sentence).han # convert into simplified chinese
if simplified == sentence: # simplified chinese already
return
sentence = list(sentence)
simplified = list(simplified)
for i in range(0, min(len(sentence), len(simplified))): # traverse each character
if sentence[i] != simplified[i]: # found different character
sentence[i] = '\033[0;33m%s\033[0;39m' % sentence[i] # set colorful flag
simplified[i] = '\033[0;32m%s\033[0;39m' % simplified[i]
print('%s\n> %s\n> %s\n%s' % (
'-' * 128, ''.join(sentence), ''.join(simplified), '-' * 128
))
traditionalCheck('繁體中文的叫法在臺灣亦很常見')
Loading…
Cancel
Save