Skip to content

Commit aa078d0

Browse files
authored
fix: only use digit-by-digit reading for 4-digit years (#349)
* feat: support nbest output in normalize/tag (#296) normalize(input, nbest=1) returns a single string (default, backward compatible). normalize(input, nbest=N) returns a list of N-best results. Example: n.normalize('海淀区108号', nbest=3) # ['海淀区一百零八号', '海淀区十八号', '海淀区幺零八号'] * fix: only use digit-by-digit reading for 4-digit years (#302) Previously 2-digit numbers followed by 年/年度/赛季 were read digit-by-digit (38年 => 三八年). Now only 4-digit years use this pattern, so 38年 => 三十八年 (via number) while 2024年 => 二零二四年.
1 parent 8cc6aee commit aa078d0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

tn/chinese/rules/measure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def build_tagger(self):
4747
measure @= self.build_rule(cross("两" + unit, "二" + unit), l="[BOS]")
4848
measure @= self.build_rule(cross("到两" + unit, "到二" + unit), r="[EOS]")
4949

50-
# -xxxx年, -xx年
50+
# xxxx年, xxxx-xxxx年
5151
digits = self.cardinal.digits
52-
cardinal = digits**2 | digits**4
52+
yyyy = digits**4
5353
unit = accep("年") | accep("年度") | accep("赛季")
54-
prefix = cardinal + (rmspace + unit).ques + to
55-
annual = prefix.ques + cardinal + unit
54+
prefix = yyyy + (rmspace + unit).ques + to
55+
annual = prefix.ques + yyyy + unit
5656

5757
tagger = insert('value: "') + (measure | annual) + insert('"')
5858

0 commit comments

Comments
 (0)