Skip to content

Commit 80956d3

Browse files
committed
feat: fix time min-to, IP twenty-three, serial, 456/470 (97%)
- Time: fix minute_to composition (use raw digits without zero-padding) => time now 29/29 full pass - Telephone: fix IP to support single+two_digit combinations (one twenty three dot... => 123.123.0.40) - Cardinal: expose graph_two_digit for telephone serial
1 parent 3935971 commit 80956d3

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

itn/english/rules/cardinal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def build_tagger(self):
3636
# 1~9, 10~19, 20~99
3737
one_digit = digit
3838
two_digit = teen | (ties + (ds + digit | insert("0")))
39+
self.graph_two_digit = two_digit
3940
up_to_99 = one_digit | two_digit
4041

4142
# one hundred, one hundred twenty three, one hundred one

itn/english/rules/telephone.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def build_tagger(self):
4040
("five","5"),("six","6"),("seven","7"),("eight","8"),
4141
("nine","9"),("zero","0"),("oh","0"),("o","0")]])
4242

43-
# two-digit cardinal: twenty three => 23
44-
two_digit = self.cardinal.graph_no_exception @ (self.DIGIT + self.DIGIT)
43+
# two-digit cardinal: twenty three => 23 (uses graph_two_digit for proper space handling)
44+
two_digit = self.cardinal.graph_two_digit
4545

4646
# a token is 1 or 2 digits
4747
token = single | double | add_weight(two_digit, 0.002)
@@ -72,7 +72,13 @@ 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) | double | add_weight(two_digit, 0.002)
75+
ip_token = (
76+
single + closure(ds + single, 0, 2)
77+
| double
78+
| add_weight(two_digit, 0.002)
79+
| single + ds + two_digit
80+
| two_digit + ds + single
81+
)
7682
ip = ip_token + (cross(" dot ", ".") + ip_token) ** 3
7783
graph |= insert('number_part: "') + add_weight(ip, -0.001) + insert('"')
7884

@@ -84,7 +90,7 @@ def build_tagger(self):
8490
graph |= insert('number_part: "') + cc + insert('"')
8591

8692
# serial: mixed alpha+digits, at least one digit, length >= 3
87-
serial_char = single | add_weight(two_digit, 0.002) | self.ALPHA
93+
serial_char = add_weight(single, 0.001) | add_weight(two_digit, -0.001) | self.ALPHA
8894
serial = serial_char + closure(ds + serial_char, 2)
8995
serial = serial @ (closure(self.ALPHA | self.DIGIT) + self.DIGIT + closure(self.ALPHA | self.DIGIT))
9096
graph |= insert('number_part: "') + add_weight(serial, 2.0) + insert('"')

itn/english/rules/time.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def build_tagger(self):
5252
graph_min_double = union(*[cross(_num_to_word(x), str(x)) for x in range(10, 60)])
5353
graph_min_verbose = cross("half", "30") | cross("quarter", "15")
5454

55+
# minutes without zero-padding (for minute_to composition)
56+
min_single_raw = union(*[cross(_num_to_word(x), str(x)) for x in range(1, 10)])
57+
min_double_raw = graph_min_double # already no padding
58+
5559
oclock = cross("o'clock", "") | cross("oclock", "") | cross("hundred hours", "")
5660

5761
hour = insert('hour: "') + hour_all + insert('"')
@@ -89,7 +93,7 @@ def build_tagger(self):
8993
# "ten to eleven pm" => 10:50 p.m.
9094
graph_min_to = (
9195
insert('minute: "')
92-
+ ((graph_min_single | graph_min_double) @ minute_to)
96+
+ ((min_single_raw | min_double_raw) @ minute_to)
9397
+ insert('"')
9498
+ closure(ds + delete("min") + delete("ute").ques + delete("s").ques, 0, 1)
9599
+ ds + delete("to") + ds

itn/english/test/data/en_telephone.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +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+
one twenty three dot one two three dot o dot four o => 123.123.0.40
1011
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
1212
ssn is seven double nine one two three double one three => ssn is 799-12-3113
1313
seven nine nine => 799
1414
a b nine => ab9

itn/english/test/data/en_time.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ quarter past one => 01:15
2626
quarter to one => 12:45
2727
quarter to twelve => 11:45
2828
set alarm at ten to eleven pm => set alarm at 10:50 p.m.
29+
one min to one am => 12:59 a.m.

0 commit comments

Comments
 (0)