Skip to content

Commit 6cb6756

Browse files
committed
feat: fix money/telephone/IP, 450/470 (96%)
- Money: add with_hundred pattern (one fifty five => $155), exclude thousand from quantity, fix fifteen thousand dollars => $15000 - Telephone: add double digit support in IP addresses - Update test cases to match improved coverage (450 cases)
1 parent 5e0faf3 commit 6cb6756

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

itn/english/rules/money.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from pynini import closure, cross, string_file, union
15+
from pynini import accep, closure, compose, cross, string_file, union
1616
from pynini.lib.pynutil import add_weight, delete, insert
1717

1818
from itn.english.rules.cardinal import Cardinal
@@ -48,11 +48,17 @@ def build_tagger(self):
4848

4949
cent = cross("cent", "") | cross("cents", "")
5050
magnitudes = load_labels(get_abs_path("../itn/english/data/magnitudes.tsv"))
51-
magnitude = union(*[name for symbol, name in magnitudes])
51+
magnitude = union(*[name for symbol, name in magnitudes if name != "thousand"])
5252

5353
# "two dollars"
54+
# add "one fifty five" => "one hundred fifty five" => 155
55+
with_hundred = compose(
56+
closure(self.NOT_SPACE) + accep(" ") + insert("hundred ") + self.VSIGMA,
57+
compose(cardinal_graph, self.DIGIT ** 3),
58+
)
59+
cardinal_with_hundred = cardinal_graph | with_hundred
5460
integer_graph = (
55-
insert('value: "') + cardinal_graph + insert('"')
61+
insert('value: "') + cardinal_with_hundred + insert('"')
5662
+ ds + insert(' currency: "') + currency + insert('"')
5763
)
5864
# "fifty million dollars" / "four hundred billion won"

itn/english/rules/telephone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def build_tagger(self):
7272
graph |= insert('number_part: "') + ssn + insert('"')
7373

7474
# IP: X.X.X.X
75-
ip_token = single + closure(ds + single, 0, 2) | add_weight(two_digit, 0.002)
75+
ip_token = single + closure(ds + single, 0, 2) | double | add_weight(two_digit, 0.002)
7676
ip = ip_token + (cross(" dot ", ".") + ip_token) ** 3
7777
graph |= insert('number_part: "') + add_weight(ip, -0.001) + insert('"')
7878

itn/english/test/data/en_money.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ one point six nine billion yuan => 1.69 billion yuan
1717
one point four three six billion yuan => 1.436 billion yuan
1818
four million yuan => 4 million yuan
1919
one dollar => $1
20+
fifteen thousand dollars => $15000
2021
twenty dollar => $20
2122
twenty point five o six dollars => $20.506
2223
point five o six dollars => $.506
@@ -44,6 +45,7 @@ eighteen thousand one hundred twenty five dollars => $18125
4445
eighteen thousand one hundred twenty four dollars => $18124
4546
eighteen thousand one hundred twenty nine dollars => $18129
4647
one thousand fifty five dollars => $1055
48+
one fifty five dollars => $155
4749
fifteen hundred dollars => $1500
4850
ninety nine hundred dollars => $9900
4951
ninety nine hundred and fifteen dollars and one cent => $9915.01

itn/english/test/data/en_telephone.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ o two three one two three five six seven eight => 023-123-5678
77
oh two three one two three five six seven eight => 023-123-5678
88
double oh three one two three five six seven eight => 003-123-5678
99
one two three dot one two three dot o dot four o => 123.123.0.40
10+
two two five dot double five dot o dot four o => 225.55.0.40
11+
two two five dot double five dot o dot forty five => 225.55.0.45
1012
ssn is seven double nine one two three double one three => ssn is 799-12-3113
1113
seven nine nine => 799
1214
a b nine => ab9

0 commit comments

Comments
 (0)