Skip to content

Commit 7de857c

Browse files
committed
fix: resolve 16 failing unit tests across Chinese ITN, Japanese ITN, and English TN
- Chinese ITN: prefer currency symbol ($) over ISO code (USD) by adding weight to code FST in money rule - Japanese ITN: fix big_integer FST structure to prevent 三十 being split into 3+10=310 instead of parsed as 30 - English TN: prefer "oh" over "zero" for digit 0 in non-deterministic mode by adding weight to zero path - English TN: fix whitelist test expectation for Hon. -> Honorable
1 parent 160a126 commit 7de857c

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

itn/chinese/rules/money.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from pynini import string_file
16-
from pynini.lib.pynutil import delete, insert
16+
from pynini.lib.pynutil import add_weight, delete, insert
1717

1818
from itn.chinese.rules.cardinal import Cardinal
1919
from tn.processor import Processor
@@ -42,7 +42,7 @@ def build_tagger(self):
4242
+ number
4343
+ insert('"')
4444
+ insert(' currency: "')
45-
+ (code | symbol)
45+
+ (symbol | add_weight(code, 1))
4646
+ insert('"')
4747
+ insert(' decimal: "')
4848
+ (insert(".") + digit + (delete("毛") | delete("角")) + (digit + delete("分")).ques).ques

itn/japanese/rules/cardinal.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,13 @@ def build_tagger(self):
122122
(ten_thousand_minus + accep("兆")).ques
123123
+ ten_thousand_minus
124124
+ accep("億")
125-
+ ten_thousand_minus
126-
+ accep("万").ques
127-
+ ten_thousand_minus.ques
125+
+ (ten_thousand_minus + (accep("万") + ten_thousand_minus.ques).ques).ques
128126
)
129127
| (
130128
ten_thousand_minus
131129
+ accep("兆")
132130
+ (ten_thousand_minus + accep("億")).ques
133-
+ ten_thousand_minus
134-
+ accep("万").ques
135-
+ ten_thousand_minus.ques
131+
+ (ten_thousand_minus + (accep("万") + ten_thousand_minus.ques).ques).ques
136132
)
137133
)
138134
self.big_integer = number | big_integer

tn/english/rules/cardinal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def build_tagger(self):
5858
single_digits_graph_zero = pynini.invert(graph_digit | graph_zero)
5959
single_digits_graph_oh = pynini.invert(graph_digit) | pynini.cross("0", "oh")
6060

61-
self.single_digits_graph = single_digits_graph_zero + (self.INSERT_SPACE + single_digits_graph_zero).star
61+
self.single_digits_graph = pynutil.add_weight(
62+
single_digits_graph_zero + (self.INSERT_SPACE + single_digits_graph_zero).star, 1.0
63+
)
6264
self.single_digits_graph |= single_digits_graph_oh + (self.INSERT_SPACE + single_digits_graph_oh).star
6365

6466
single_digits_graph_with_commas = (

tn/english/test/data/whitelist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Ph.D. => PHD
2-
Hon. => honorable
2+
Hon. => Honorable
33
Mt. => Mount
44
Maj. => Major
55
Rev. => Reverend

0 commit comments

Comments
 (0)