add negative numbers and decimals for re range
This commit is contained in:
parent
cf26e2932b
commit
06cbdb1ebd
|
@ -162,8 +162,9 @@ def replace_number(match) -> str:
|
||||||
|
|
||||||
|
|
||||||
# 范围表达式
|
# 范围表达式
|
||||||
# 12-23, 12~23
|
# match.group(1) and match.group(8) are copy from RE_NUMBER
|
||||||
RE_RANGE = re.compile(r'(\d+)[-~](\d+)')
|
RE_RANGE = re.compile(
|
||||||
|
r'((-?)((\d+)(\.\d+)?)|(\.(\d+)))[-~]((-?)((\d+)(\.\d+)?)|(\.(\d+)))')
|
||||||
|
|
||||||
|
|
||||||
def replace_range(match) -> str:
|
def replace_range(match) -> str:
|
||||||
|
@ -175,9 +176,9 @@ def replace_range(match) -> str:
|
||||||
----------
|
----------
|
||||||
str
|
str
|
||||||
"""
|
"""
|
||||||
first, second = match.group(1), match.group(2)
|
first, second = match.group(1), match.group(8)
|
||||||
first: str = num2str(first)
|
first = RE_NUMBER.sub(replace_number, first)
|
||||||
second: str = num2str(second)
|
second = RE_NUMBER.sub(replace_number, second)
|
||||||
result = f"{first}到{second}"
|
result = f"{first}到{second}"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -241,7 +242,8 @@ def num2str(value_string: str) -> str:
|
||||||
|
|
||||||
decimal = decimal.rstrip('0')
|
decimal = decimal.rstrip('0')
|
||||||
if decimal:
|
if decimal:
|
||||||
# '.22' is verbalized as '点二二'
|
# '.22' is verbalized as '零点二二'
|
||||||
# '3.20' is verbalized as '三点二
|
# '3.20' is verbalized as '三点二
|
||||||
|
result = result if result else "零"
|
||||||
result += '点' + verbalize_digit(decimal)
|
result += '点' + verbalize_digit(decimal)
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue