@@ -28,90 +28,48 @@ def __init__(self):
2828
2929 def build_tagger (self ):
3030 ds = delete (" " )
31-
32- # Single characters: digits and letters
3331 digit = string_file (get_abs_path ("../itn/english/data/numbers/digit.tsv" ))
3432 zero = string_file (get_abs_path ("../itn/english/data/numbers/zero.tsv" ))
35- alpha_or_digit = self .ALPHA | digit | zero
36-
37- # Symbols from TSV (symbol\tname): invert to get name -> symbol
38- symbols = invert (
39- string_file (get_abs_path ("../itn/english/data/electronic/symbols.tsv" ))
40- )
41-
42- # A "token" is either a single char (letter/digit/symbol) or a
43- # multi-letter word kept verbatim (e.g. "gmail", "nvidia").
44- # Multi-letter words have lower priority so spelled-out letters are preferred.
45- word = add_weight (closure (self .ALPHA , 2 ), 0.01 )
46- token = alpha_or_digit | symbols | word
33+ symbols = invert (string_file (get_abs_path ("../itn/english/data/electronic/symbols.tsv" )))
4734
48- # A component is one or more tokens separated by spaces
35+ char = self .ALPHA | digit | zero
36+ word = add_weight (closure (self .ALPHA , 2 ), 0.1 )
37+ token = char | symbols | word
4938 component = token + closure (ds + token )
5039
40+ dot = cross ("dot" , "." )
41+ domain = component + (ds + dot + ds + component ).plus
42+
5143 username = insert ('username: "' ) + component + insert ('"' )
44+ domain_field = insert ('domain: "' ) + domain + insert ('"' )
5245
53- # Domain: component(s) separated by "dot" => "."
54- dot = cross ("dot" , "." )
55- domain_content = component + closure (ds + dot + ds + component )
56- domain = insert ('domain: "' ) + domain_content + insert ('"' )
57-
58- # Email: username at domain
59- graph_email = (
60- username
61- + ds
62- + delete ("at" )
63- + ds
64- + insert (" " )
65- + domain
66- )
67-
68- # URL protocol: "h t t p colon slash slash" or "h t t p s colon slash slash"
46+ # Email: X at Y dot Z (requires "at" keyword)
47+ graph_email = username + ds + delete ("at" ) + ds + insert (" " ) + domain_field
48+
49+ # URL: requires protocol or www prefix
6950 http = cross ("h t t p" , "http" )
7051 https = cross ("h t t p s" , "https" )
71- colon_slash_slash = cross (" colon slash slash " , "://" )
72- protocol_start = (http | https ) + colon_slash_slash
73-
74- # www prefix
52+ protocol = (http | https ) + cross (" colon slash slash " , "://" )
7553 www = cross ("w w w" , "www" )
7654
77- # URL: [protocol] [www.] domain
78- url_content = (
79- closure (protocol_start , 0 , 1 )
80- + closure (www + ds + dot + ds , 0 , 1 )
81- + domain_content
82- )
83- graph_url = insert ('protocol: "' ) + url_content + insert ('"' )
55+ # protocol + [www.] + domain
56+ url_with_protocol = protocol + closure (www + ds + dot + ds , 0 , 1 ) + domain
57+ # www. + domain (no protocol)
58+ url_with_www = www + ds + dot + ds + domain
59+ # domain only (must have dot): nvidia dot com
60+ url_domain_only = domain
61+
62+ graph_url = insert ('protocol: "' ) + (url_with_protocol | url_with_www | url_domain_only ) + insert ('"' )
8463
8564 final_graph = graph_email | graph_url
8665 self .tagger = self .add_tokens (final_graph )
8766
8867 def build_verbalizer (self ):
89- username = (
90- delete ("username:" )
91- + self .DELETE_SPACE
92- + delete ('"' )
93- + self .NOT_QUOTE .plus
94- + delete ('"' )
95- )
96- domain = (
97- delete ("domain:" )
98- + self .DELETE_SPACE
99- + delete ('"' )
100- + self .NOT_QUOTE .plus
101- + delete ('"' )
102- )
103- protocol = (
104- delete ("protocol:" )
105- + self .DELETE_SPACE
106- + delete ('"' )
107- + self .NOT_QUOTE .plus
108- + delete ('"' )
109- )
110-
111- # Email: username@domain
68+ username = delete ("username:" ) + self .DELETE_SPACE + delete ('"' ) + self .NOT_QUOTE .plus + delete ('"' )
69+ domain = delete ("domain:" ) + self .DELETE_SPACE + delete ('"' ) + self .NOT_QUOTE .plus + delete ('"' )
70+ protocol = delete ("protocol:" ) + self .DELETE_SPACE + delete ('"' ) + self .NOT_QUOTE .plus + delete ('"' )
71+
11272 graph_email = username + self .DELETE_SPACE + insert ("@" ) + domain
113- # URL: just output the protocol content directly
11473 graph_url = protocol
11574
116- graph = graph_email | graph_url
117- self .verbalizer = self .delete_tokens (graph )
75+ self .verbalizer = self .delete_tokens (graph_email | graph_url )
0 commit comments