(chinese_string, numbering_type=NUMBERING_TYPES[1])
| 610 | |
| 611 | |
| 612 | def chn2num(chinese_string, numbering_type=NUMBERING_TYPES[1]): |
| 613 | def get_symbol(char, system): |
| 614 | for u in system.units: |
| 615 | if char in [u.traditional, u.simplified, u.big_s, u.big_t]: |
| 616 | return u |
| 617 | for d in system.digits: |
| 618 | if char in [ |
| 619 | d.traditional, |
| 620 | d.simplified, |
| 621 | d.big_s, |
| 622 | d.big_t, |
| 623 | d.alt_s, |
| 624 | d.alt_t, |
| 625 | ]: |
| 626 | return d |
| 627 | for m in system.math: |
| 628 | if char in [m.traditional, m.simplified]: |
| 629 | return m |
| 630 | |
| 631 | def string2symbols(chinese_string, system): |
| 632 | int_string, dec_string = chinese_string, "" |
| 633 | for p in [system.math.point.simplified, system.math.point.traditional]: |
| 634 | if p in chinese_string: |
| 635 | int_string, dec_string = chinese_string.split(p) |
| 636 | break |
| 637 | return [get_symbol(c, system) for c in int_string], [ |
| 638 | get_symbol(c, system) for c in dec_string |
| 639 | ] |
| 640 | |
| 641 | def correct_symbols(integer_symbols, system): |
| 642 | """ |
| 643 | 一百八 to 一百八十 |
| 644 | 一亿一千三百万 to 一亿 一千万 三百万 |
| 645 | """ |
| 646 | |
| 647 | if integer_symbols and isinstance(integer_symbols[0], CNU): |
| 648 | if integer_symbols[0].power == 1: |
| 649 | integer_symbols = [system.digits[1]] + integer_symbols |
| 650 | |
| 651 | if len(integer_symbols) > 1: |
| 652 | if isinstance(integer_symbols[-1], CND) and isinstance( |
| 653 | integer_symbols[-2], CNU |
| 654 | ): |
| 655 | integer_symbols.append( |
| 656 | CNU(integer_symbols[-2].power - 1, None, None, None, None) |
| 657 | ) |
| 658 | |
| 659 | result = [] |
| 660 | unit_count = 0 |
| 661 | for s in integer_symbols: |
| 662 | if isinstance(s, CND): |
| 663 | result.append(s) |
| 664 | unit_count = 0 |
| 665 | elif isinstance(s, CNU): |
| 666 | current_unit = CNU(s.power, None, None, None, None) |
| 667 | unit_count += 1 |
| 668 | |
| 669 | if unit_count == 1: |
no test coverage detected