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

Function compute_value

utils/text_norm.py:288–306  ·  view source on GitHub ↗

Compute the value. When current unit is larger than previous unit, current unit * all previous units will be used as all previous units. e.g. '两千万' = 2000 * 10000 not 2000 + 10000

(integer_symbols)

Source from the content-addressed store, hash-verified

286 return result
287
288 def compute_value(integer_symbols):
289 """
290 Compute the value.
291 When current unit is larger than previous unit, current unit * all previous units will be used as all previous units.
292 e.g. '两千万' = 2000 * 10000 not 2000 + 10000
293 """
294 value = [0]
295 last_power = 0
296 for s in integer_symbols:
297 if isinstance(s, CND):
298 value[-1] = s.value
299 elif isinstance(s, CNU):
300 value[-1] *= pow(10, s.power)
301 if s.power > last_power:
302 value[:-1] = list(map(lambda v: v *
303 pow(10, s.power), value[:-1]))
304 last_power = s.power
305 value.append(0)
306 return sum(value)
307
308 system = create_system(numbering_type)
309 int_part, dec_part = string2symbols(chinese_string, system)

Callers 1

chn2numFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected