@@ -37,14 +37,15 @@ def build_tagger(self):
3737 ds = delete (" " )
3838
3939 currency_labels = load_labels (get_abs_path ("../itn/english/data/currency.tsv" ))
40- currency_pairs = []
41- for symbol , name in currency_labels :
42- currency_pairs . append (( name , symbol ))
40+ singular_pairs = [( name , symbol ) for symbol , name in currency_labels ]
41+ plural_pairs = []
42+ for name , symbol in singular_pairs :
4343 if name .endswith ("s" ):
44- currency_pairs .append ((name + "es" , symbol ))
44+ plural_pairs .append ((name + "es" , symbol ))
4545 else :
46- currency_pairs .append ((name + "s" , symbol ))
47- currency = union (* [cross (name , symbol ) for name , symbol in currency_pairs ]).optimize ()
46+ plural_pairs .append ((name + "s" , symbol ))
47+ currency_singular = union (* [cross (name , symbol ) for name , symbol in singular_pairs ]).optimize ()
48+ currency_plural = union (* [cross (name , symbol ) for name , symbol in singular_pairs + plural_pairs ]).optimize ()
4849
4950 cent = cross ("cent" , "" ) | cross ("cents" , "" )
5051 magnitudes = load_labels (get_abs_path ("../itn/english/data/magnitudes.tsv" ))
@@ -57,15 +58,23 @@ def build_tagger(self):
5758 compose (cardinal_graph , self .DIGIT ** 3 ),
5859 )
5960 cardinal_with_hundred = cardinal_graph | with_hundred
61+ not_one = self .DIGIT ** (2 , ...) | (self .DIGIT - accep ("1" ))
62+ cardinal_plural = compose (cardinal_with_hundred , not_one )
63+ # "one dollar" (singular) vs "two dollars" (plural)
64+ one = cross ("one" , "1" )
6065 integer_graph = (
61- insert ('value: "' ) + cardinal_with_hundred + insert ('"' )
62- + ds + insert (' currency: "' ) + currency + insert ('"' )
66+ insert ('value: "' ) + cardinal_plural + insert ('"' )
67+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
68+ )
69+ integer_graph |= (
70+ insert ('value: "' ) + one + insert ('"' )
71+ + ds + insert (' currency: "' ) + currency_singular + insert ('"' )
6372 )
6473 # "fifty million dollars" / "four hundred billion won"
6574 quantity_graph = (
6675 insert ('value: "' ) + cardinal_small + insert ('"' )
6776 + ds + insert (' quantity: "' ) + magnitude + insert ('"' )
68- + ds + insert (' currency: "' ) + currency + insert ('"' )
77+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
6978 )
7079 # "two point five billion dollars"
7180 digit = string_file (get_abs_path ("../itn/english/data/numbers/digit.tsv" ))
@@ -76,38 +85,38 @@ def build_tagger(self):
7685 insert ('value: "' ) + cardinal_graph + insert ("." )
7786 + ds + delete ("point" ) + ds + frac + insert ('"' )
7887 + ds + insert (' quantity: "' ) + magnitude + insert ('"' )
79- + ds + insert (' currency: "' ) + currency + insert ('"' )
88+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
8089 )
8190 # "twenty point five o six dollars" (decimal without quantity)
8291 decimal_graph = (
8392 insert ('value: "' ) + cardinal_graph + insert ("." )
8493 + ds + delete ("point" ) + ds + frac + insert ('"' )
85- + ds + insert (' currency: "' ) + currency + insert ('"' )
94+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
8695 )
8796 # "point five o six dollars"
8897 decimal_no_int = (
8998 insert ('value: ".' ) + delete ("point" ) + ds + frac + insert ('"' )
90- + ds + insert (' currency: "' ) + currency + insert ('"' )
99+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
91100 )
92101 # "one fifty five dollars" => $155 (missing "hundred")
93102 with_hundred = (
94103 insert ('value: "' ) + cardinal_small + insert ('"' )
95- + ds + insert (' currency: "' ) + currency + insert ('"' )
104+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
96105 )
97106
98107 # cents
99108 cents_graph = union (* [cross (_num_to_word (x ), f"{ x :02d} " ) for x in range (1 , 100 ) if _num_to_word (x )])
100109 with_cents = (
101110 insert ('value: "' ) + cardinal_graph + insert ('"' )
102- + ds + insert (' currency: "' ) + currency + insert ('"' )
111+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
103112 + ds + (delete ("and" ) + ds ).ques
104113 + insert (' decimal: "' ) + cents_graph + insert ('"' )
105114 + ds + cent
106115 )
107116 # "seventy five dollars sixty three" (no "cents" word)
108117 dollars_amount = (
109118 insert ('value: "' ) + cardinal_graph + insert ('"' )
110- + ds + insert (' currency: "' ) + currency + insert ('"' )
119+ + ds + insert (' currency: "' ) + currency_plural + insert ('"' )
111120 + ds + insert (' decimal: "' ) + cents_graph + insert ('"' )
112121 )
113122 cents_only = (
0 commit comments