Skip to content

Commit b3ed6af

Browse files
committed
fix: don't convert - to 减 in non-math context (#294)
Split math operators into ambiguous (-, +, =) and unambiguous (×, ÷, ≥, ≤, etc.). Ambiguous operators now require number context on both sides. Unambiguous operators can still match independently. Before: wide-awake => wide减awake After: wide-awake => wide-awake
1 parent 0650fa9 commit b3ed6af

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
×
2+
÷
3+
大于等于
4+
小于等于
5+
>= 大于等于
6+
<= 小于等于

tn/chinese/rules/math.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def __init__(self, cardinal=None):
3030

3131
def build_tagger(self):
3232
operator = string_file(get_abs_path("chinese/data/math/operator.tsv"))
33+
unambiguous_operator = string_file(get_abs_path("chinese/data/math/operator_unambiguous.tsv"))
3334
symbols = cross("~", "到") | cross(":", "比") | cross("<", "小于") | cross(">", "大于")
3435

3536
number = self.cardinal.number
3637
tagger = number + (delete(" ").ques + (operator | symbols) + delete(" ").ques + number).star
37-
tagger |= operator
38+
tagger |= unambiguous_operator
3839
tagger = insert('value: "') + tagger + insert('"')
3940
self.tagger = self.add_tokens(tagger)

0 commit comments

Comments
 (0)