MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / create_system

Function create_system

utils/text_norm.py:191–230  ·  view source on GitHub ↗

根据数字系统类型返回创建相应的数字系统,默认为 mid NUMBERING_TYPES = ['low', 'mid', 'high']: 中文数字系统类型 low: '兆' = '亿' * '十' = $10^{9}$, '京' = '兆' * '十', etc. mid: '兆' = '亿' * '万' = $10^{12}$, '京' = '兆' * '万', etc. high: '兆' = '亿' * '亿' = $10^{16}$, '京' = '兆' * '兆', etc. 返回对应的数字系统

(numbering_type=NUMBERING_TYPES[1])

Source from the content-addressed store, hash-verified

189# basic utils
190# ================================================================================ #
191def create_system(numbering_type=NUMBERING_TYPES[1]):
192 """
193 根据数字系统类型返回创建相应的数字系统,默认为 mid
194 NUMBERING_TYPES = ['low', 'mid', 'high']: 中文数字系统类型
195 low: '兆' = '亿' * '十' = $10^{9}$, '京' = '兆' * '十', etc.
196 mid: '兆' = '亿' * '万' = $10^{12}$, '京' = '兆' * '万', etc.
197 high: '兆' = '亿' * '亿' = $10^{16}$, '京' = '兆' * '兆', etc.
198 返回对应的数字系统
199 """
200
201 # chinese number units of '亿' and larger
202 all_larger_units = zip(
203 LARGER_CHINESE_NUMERING_UNITS_SIMPLIFIED, LARGER_CHINESE_NUMERING_UNITS_TRADITIONAL)
204 larger_units = [CNU.create(i, v, numbering_type, False)
205 for i, v in enumerate(all_larger_units)]
206 # chinese number units of '十, 百, 千, 万'
207 all_smaller_units = zip(
208 SMALLER_CHINESE_NUMERING_UNITS_SIMPLIFIED, SMALLER_CHINESE_NUMERING_UNITS_TRADITIONAL)
209 smaller_units = [CNU.create(i, v, small_unit=True)
210 for i, v in enumerate(all_smaller_units)]
211 # digis
212 chinese_digis = zip(CHINESE_DIGIS, CHINESE_DIGIS,
213 BIG_CHINESE_DIGIS_SIMPLIFIED, BIG_CHINESE_DIGIS_TRADITIONAL)
214 digits = [CND.create(i, v) for i, v in enumerate(chinese_digis)]
215 digits[0].alt_s, digits[0].alt_t = ZERO_ALT, ZERO_ALT
216 digits[1].alt_s, digits[1].alt_t = ONE_ALT, ONE_ALT
217 digits[2].alt_s, digits[2].alt_t = TWO_ALTS[0], TWO_ALTS[1]
218
219 # symbols
220 positive_cn = CM(POSITIVE[0], POSITIVE[1], '+', lambda x: x)
221 negative_cn = CM(NEGATIVE[0], NEGATIVE[1], '-', lambda x: -x)
222 point_cn = CM(POINT[0], POINT[1], '.', lambda x,
223 y: float(str(x) + '.' + str(y)))
224 # sil_cn = CM(SIL[0], SIL[1], '-', lambda x, y: float(str(x) + '-' + str(y)))
225 system = NumberSystem()
226 system.units = smaller_units + larger_units
227 system.digits = digits
228 system.math = MathSymbol(positive_cn, negative_cn, point_cn)
229 # system.symbols = OtherSymbol(sil_cn)
230 return system
231
232
233def chn2num(chinese_string, numbering_type=NUMBERING_TYPES[1]):

Callers 2

chn2numFunction · 0.85
num2chnFunction · 0.85

Calls 3

NumberSystemClass · 0.85
MathSymbolClass · 0.85
createMethod · 0.45

Tested by

no test coverage detected