MCPcopy Create free account
hub / github.com/FunAudioLLM/Fun-ASR / compute_value

Function compute_value

tools/cn_tn.py:686–703  ·  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

684 return result
685
686 def compute_value(integer_symbols):
687 """
688 Compute the value.
689 When current unit is larger than previous unit, current unit * all previous units will be used as all previous units.
690 e.g. '两千万' = 2000 * 10000 not 2000 + 10000
691 """
692 value = [0]
693 last_power = 0
694 for s in integer_symbols:
695 if isinstance(s, CND):
696 value[-1] = s.value
697 elif isinstance(s, CNU):
698 value[-1] *= pow(10, s.power)
699 if s.power > last_power:
700 value[:-1] = list(map(lambda v: v * pow(10, s.power), value[:-1]))
701 last_power = s.power
702 value.append(0)
703 return sum(value)
704
705 system = create_system(numbering_type)
706 int_part, dec_part = string2symbols(chinese_string, system)

Callers 1

chn2numFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected