diff --git a/parakeet/frontend/cn_normalization/chronology.py b/parakeet/frontend/cn_normalization/chronology.py index 1d9520e..b8d7115 100644 --- a/parakeet/frontend/cn_normalization/chronology.py +++ b/parakeet/frontend/cn_normalization/chronology.py @@ -33,7 +33,15 @@ RE_TIME = re.compile(r'([0-1]?[0-9]|2[0-3])' r'(:([0-5][0-9]))?') -def replace_time(match: re.Match) -> str: +def replace_time(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ hour = match.group(1) minute = match.group(2) second = match.group(4) @@ -51,7 +59,15 @@ RE_DATE = re.compile(r'(\d{4}|\d{2})年' r'(((0?[1-9])|((1|2)[0-9])|30|31)([日号]))?') -def replace_date(match: re.Match) -> str: +def replace_date(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ year = match.group(1) month = match.group(3) day = match.group(5) @@ -70,7 +86,15 @@ RE_DATE2 = re.compile( r'(\d{4})([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])') -def replace_date2(match: re.Match) -> str: +def replace_date2(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ year = match.group(1) month = match.group(3) day = match.group(4) diff --git a/parakeet/frontend/cn_normalization/num.py b/parakeet/frontend/cn_normalization/num.py index e07dd80..4b7c05f 100644 --- a/parakeet/frontend/cn_normalization/num.py +++ b/parakeet/frontend/cn_normalization/num.py @@ -34,7 +34,15 @@ COM_QUANTIFIERS = '(朵|匹|张|座|回|场|尾|条|个|首|阙|阵|网|炮|顶| RE_FRAC = re.compile(r'(-?)(\d+)/(\d+)') -def replace_frac(match: re.Match) -> str: +def replace_frac(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ sign = match.group(1) nominator = match.group(2) denominator = match.group(3) @@ -49,7 +57,15 @@ def replace_frac(match: re.Match) -> str: RE_PERCENTAGE = re.compile(r'(-?)(\d+(\.\d+)?)%') -def replace_percentage(match: re.Match) -> str: +def replace_percentage(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ sign = match.group(1) percent = match.group(2) sign: str = "负" if sign else "" @@ -63,7 +79,15 @@ def replace_percentage(match: re.Match) -> str: RE_INTEGER = re.compile(r'(-)' r'(\d+)') -def replace_negative_num(match: re.Match) -> str: +def replace_negative_num(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ sign = match.group(1) number = match.group(2) sign: str = "负" if sign else "" @@ -77,7 +101,15 @@ def replace_negative_num(match: re.Match) -> str: RE_DEFAULT_NUM = re.compile(r'\d{3}\d*') -def replace_default_num(match: re.Match): +def replace_default_num(match): + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ number = match.group(0) return verbalize_digit(number) @@ -90,7 +122,15 @@ RE_POSITIVE_QUANTIFIERS = re.compile(r"(\d+)([多余几])?" + COM_QUANTIFIERS) RE_NUMBER = re.compile(r'(-?)((\d+)(\.\d+)?)' r'|(\.(\d+))') -def replace_positive_quantifier(match: re.Match) -> str: +def replace_positive_quantifier(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ number = match.group(1) match_2 = match.group(2) match_2: str = match_2 if match_2 else "" @@ -100,7 +140,15 @@ def replace_positive_quantifier(match: re.Match) -> str: return result -def replace_number(match: re.Match) -> str: +def replace_number(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ sign = match.group(1) number = match.group(2) pure_decimal = match.group(5) @@ -118,7 +166,15 @@ def replace_number(match: re.Match) -> str: RE_RANGE = re.compile(r'(\d+)[-~](\d+)') -def replace_range(match: re.Match) -> str: +def replace_range(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ first, second = match.group(1), match.group(2) first: str = num2str(first) second: str = num2str(second) diff --git a/parakeet/frontend/cn_normalization/phonecode.py b/parakeet/frontend/cn_normalization/phonecode.py index 437348c..be159c2 100644 --- a/parakeet/frontend/cn_normalization/phonecode.py +++ b/parakeet/frontend/cn_normalization/phonecode.py @@ -40,9 +40,25 @@ def phone2str(phone_string: str, mobile=True) -> str: return result -def replace_phone(match: re.Match) -> str: +def replace_phone(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ return phone2str(match.group(0), mobile=False) -def replace_mobile(match: re.Match) -> str: +def replace_mobile(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ return phone2str(match.group(0)) diff --git a/parakeet/frontend/cn_normalization/quantifier.py b/parakeet/frontend/cn_normalization/quantifier.py index f40867f..d3805a3 100644 --- a/parakeet/frontend/cn_normalization/quantifier.py +++ b/parakeet/frontend/cn_normalization/quantifier.py @@ -20,7 +20,15 @@ from .num import num2str RE_TEMPERATURE = re.compile(r'(-?)(\d+(\.\d+)?)(°C|℃|度|摄氏度)') -def replace_temperature(match: re.Match) -> str: +def replace_temperature(match) -> str: + """ + Parameters + ---------- + match : re.Match + Returns + ---------- + str + """ sign = match.group(1) temperature = match.group(2) unit = match.group(3)