| 1711 | |
| 1712 | |
| 1713 | def transform_lower_num(data_str: str): |
| 1714 | num_map = { |
| 1715 | "一": "1", |
| 1716 | "二": "2", |
| 1717 | "两": "2", |
| 1718 | "三": "3", |
| 1719 | "四": "4", |
| 1720 | "五": "5", |
| 1721 | "六": "6", |
| 1722 | "七": "7", |
| 1723 | "八": "8", |
| 1724 | "九": "9", |
| 1725 | "十": "0", |
| 1726 | } |
| 1727 | pattern = f'[{"|".join(num_map.keys())}|零]' |
| 1728 | res = re.search(pattern, data_str) |
| 1729 | if not res: |
| 1730 | # 如果字符串中没有包含中文数字 不做处理 直接返回 |
| 1731 | return data_str |
| 1732 | |
| 1733 | data_str = data_str.replace("0", "零") |
| 1734 | for n in num_map: |
| 1735 | data_str = data_str.replace(n, num_map[n]) |
| 1736 | |
| 1737 | re_data_str = re.findall("\d+", data_str) |
| 1738 | for i in re_data_str: |
| 1739 | if len(i) == 3: |
| 1740 | new_i = i.replace("0", "") |
| 1741 | data_str = data_str.replace(i, new_i, 1) |
| 1742 | elif len(i) == 4: |
| 1743 | new_i = i.replace("10", "") |
| 1744 | data_str = data_str.replace(i, new_i, 1) |
| 1745 | elif len(i) == 2 and int(i) < 10: |
| 1746 | new_i = int(i) + 10 |
| 1747 | data_str = data_str.replace(i, str(new_i), 1) |
| 1748 | elif len(i) == 1 and int(i) == 0: |
| 1749 | new_i = int(i) + 10 |
| 1750 | data_str = data_str.replace(i, str(new_i), 1) |
| 1751 | |
| 1752 | return data_str.replace("零", "0") |
| 1753 | |
| 1754 | |
| 1755 | @run_safe_model("format_time") |