Skip to content

Commit 7b2c5fc

Browse files
authored
fix #155 (#196)
1 parent 002625a commit 7b2c5fc

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

tn/chinese/data/math/operator.tsv

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
×
22
-
3-
~
43
+
5-
:
64
= 等于
75
÷
8-
< 小于
9-
> 大于
106
大于等于
117
小于等于
128
>= 大于等于

tn/chinese/rules/math.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@
1515
from tn.chinese.rules.cardinal import Cardinal
1616
from tn.processor import Processor
1717

18-
from pynini import string_file
18+
from pynini import cross, string_file
1919
from pynini.lib.pynutil import delete, insert
2020

2121

2222
class Math(Processor):
2323

2424
def __init__(self):
25-
super().__init__(name='math')
25+
super().__init__(name="math")
2626
self.build_tagger()
2727
self.build_verbalizer()
2828

2929
def build_tagger(self):
30-
operator = string_file('tn/chinese/data/math/operator.tsv')
30+
operator = string_file("tn/chinese/data/math/operator.tsv")
31+
# When it appears alone, it is treated as punctuation
32+
symbols = (
33+
cross("~", "到")
34+
| cross(":", "比")
35+
| cross("<", "小于")
36+
| cross(">", "大于")
37+
)
3138

3239
number = Cardinal().number
33-
tagger = (number + ((delete(' ').ques + operator + delete(' ').ques +
34-
number).plus).ques)
40+
tagger = (
41+
number
42+
+ (delete(" ").ques + (operator | symbols) + delete(" ").ques + number).star
43+
)
3544
tagger |= operator
3645
tagger = insert('value: "') + tagger + insert('"')
3746
self.tagger = self.add_tokens(tagger)

0 commit comments

Comments
 (0)