From 183463df0501166fc0e2fe21e0c4b7b2df35ff06 Mon Sep 17 00:00:00 2001 From: Ayaka Mikazuki Date: Tue, 26 Apr 2022 12:09:44 +0800 Subject: [PATCH] Add experimental cnt support --- README.md | 3 +++ setup.py | 2 +- src/StarCC/Dicts.py | 2 ++ src/StarCC/__init__.py | 6 ++++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2420482..4206013 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,7 @@ convert('拥有 116 年历史') # Wrong: 擁有 116 年曆史 - `cn`: Simplified Chinese (Mainland China) - `hk`: Traditional Chinese (Hong Kong) - `tw`: Traditional Chinese (Taiwan) +- `cnt`: Traditional Chinese (Mainland China) - `jp`: Japanese Shinjitai + +The support of `cnt` is currently experimental. diff --git a/setup.py b/setup.py index 8e93626..f1a817b 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='starcc', - version='0.0.3', + version='0.0.4', description='Python implementation of StarCC', long_description=long_description, long_description_content_type='text/markdown', diff --git a/src/StarCC/Dicts.py b/src/StarCC/Dicts.py index c9de56b..b4f7569 100644 --- a/src/StarCC/Dicts.py +++ b/src/StarCC/Dicts.py @@ -3,10 +3,12 @@ class Dicts: TW2ST = ('TWVariantsRev', 'TWVariantsRevPhrases') TWP2ST = ('TWVariantsRev', 'TWVariantsRevPhrases', 'TWPhrasesRev') HK2ST = ('HKVariantsRev', 'HKVariantsRevPhrases') + CNT2ST = ('CNTradVariantsRev', 'CNTradRevPhrases'), JP2ST = ('JPVariantsRev', 'JPShinjitaiCharacters', 'JPShinjitaiPhrases') ST2CN = ('TSCharacters', 'TSPhrases') ST2HK = ('HKVariants',) ST2TW = ('TWVariants',) ST2TWP = ('TWVariants', 'TWPhrasesIT', 'TWPhrasesName', 'TWPhrasesOther') + ST2CNT = ('CNTradVariants', 'CNTradPhrases') ST2JP = ('JPVariants',) diff --git a/src/StarCC/__init__.py b/src/StarCC/__init__.py index f772515..46b86c2 100644 --- a/src/StarCC/__init__.py +++ b/src/StarCC/__init__.py @@ -97,9 +97,9 @@ def __init__(self, src: str='cn', dst: str='hk', with_phrase: bool=False, use_se from Simplified to Traditional, this option has no effect. ''' - if src not in ('st', 'cn', 'hk', 'tw', 'jp'): + if src not in ('st', 'cn', 'hk', 'tw', 'cnt', 'jp'): raise ValueError(f'Invalid src value: {src}') - if dst not in ('st', 'cn', 'hk', 'tw', 'jp'): + if dst not in ('st', 'cn', 'hk', 'tw', 'cnt', 'jp'): raise ValueError(f'Invalid dst value: {dst}') assert src != dst @@ -112,6 +112,7 @@ def __init__(self, src: str='cn', dst: str='hk', with_phrase: bool=False, use_se 'cn': Dicts.CN2ST, 'hk': Dicts.HK2ST, 'tw': Dicts.TW2ST, + 'cnt': Dicts.CNT2ST, 'jp': Dicts.JP2ST, }[src]) else: # with_phrase @@ -134,6 +135,7 @@ def __init__(self, src: str='cn', dst: str='hk', with_phrase: bool=False, use_se 'cn': Dicts.ST2CN, 'hk': Dicts.ST2HK, 'tw': Dicts.ST2TW, + 'cnt': Dicts.ST2CNT, 'jp': Dicts.ST2JP, }[dst]) else: # with_phrase