WeTextProcessing 1.0.2__py3-none-any.whl → 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/METADATA +29 -9
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/RECORD +16 -15
- itn/chinese/data/default/whitelist.tsv +15 -0
- itn/chinese/data/number/digit_zh.tsv +10 -0
- itn/chinese/rules/measure.py +34 -2
- itn/zh_itn_tagger.fst +0 -0
- tn/en_tn_tagger.fst +0 -0
- tn/en_tn_verbalizer.fst +0 -0
- tn/english/data/whitelist/tts.tsv +6 -0
- tn/english/normalizer.py +29 -13
- tn/english/rules/punctuation.py +9 -5
- tn/main.py +2 -3
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/LICENSE +0 -0
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/WHEEL +0 -0
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/entry_points.txt +0 -0
- {WeTextProcessing-1.0.2.dist-info → WeTextProcessing-1.0.3.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: WeTextProcessing
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: WeTextProcessing, including TN & ITN
|
|
5
5
|
Home-page: https://github.com/wenet-e2e/WeTextProcessing
|
|
6
6
|
Author: Zhendong Peng, Xingchen Song
|
|
@@ -51,14 +51,34 @@ weitn --text "二点五平方电线"
|
|
|
51
51
|
Python usage:
|
|
52
52
|
|
|
53
53
|
```py
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
from itn.chinese.inverse_normalizer import InverseNormalizer
|
|
55
|
+
from tn.chinese.normalizer import Normalizer as ZhNormalizer
|
|
56
|
+
from tn.english.normalizer import Normalizer as EnNormalizer
|
|
57
|
+
|
|
58
|
+
# NOTE(xcsong): 和默认参数不一致时,必须重新构图,要重新构图请务必指定 `overwrite_cache=True`
|
|
59
|
+
# When the parameters differ from the defaults, it is mandatory to re-compose. To re-compose, please ensure you specify `overwrite_cache=True`.
|
|
60
|
+
|
|
61
|
+
zh_tn_text = "你好 WeTextProcessing 1.0,船新版本儿,船新体验儿,简直666,9和10"
|
|
62
|
+
zh_itn_text = "你好 WeTextProcessing 一点零,船新版本儿,船新体验儿,简直六六六,九和六"
|
|
63
|
+
en_tn_text = "Hello WeTextProcessing 1.0, life is short, just use wetext, 666, 9 and 10"
|
|
64
|
+
zh_tn_model = ZhNormalizer(remove_erhua=True, overwrite_cache=True)
|
|
65
|
+
zh_itn_model = InverseNormalizer(enable_0_to_9=False, overwrite_cache=True)
|
|
66
|
+
en_tn_model = EnNormalizer(overwrite_cache=True)
|
|
67
|
+
print("中文 TN (去除儿化音,重新在线构图):\n\t{} => {}".format(zh_tn_text, zh_tn_model.normalize(zh_tn_text)))
|
|
68
|
+
print("中文ITN (小于10的单独数字不转换,重新在线构图):\n\t{} => {}".format(zh_itn_text, zh_itn_model.normalize(zh_itn_text)))
|
|
69
|
+
print("英文 TN (暂时还没有可控的选项,后面会加...):\n\t{} => {}\n".format(en_tn_text, en_tn_model.normalize(en_tn_text)))
|
|
70
|
+
|
|
71
|
+
zh_tn_model = ZhNormalizer(overwrite_cache=False)
|
|
72
|
+
zh_itn_model = InverseNormalizer(overwrite_cache=False)
|
|
73
|
+
en_tn_model = EnNormalizer(overwrite_cache=False)
|
|
74
|
+
print("中文 TN (复用之前编译好的图):\n\t{} => {}".format(zh_tn_text, zh_tn_model.normalize(zh_tn_text)))
|
|
75
|
+
print("中文ITN (复用之前编译好的图):\n\t{} => {}".format(zh_itn_text, zh_itn_model.normalize(zh_itn_text)))
|
|
76
|
+
print("英文 TN (复用之前编译好的图):\n\t{} => {}\n".format(en_tn_text, en_tn_model.normalize(en_tn_text)))
|
|
77
|
+
|
|
78
|
+
zh_tn_model = ZhNormalizer(remove_erhua=False, overwrite_cache=True)
|
|
79
|
+
zh_itn_model = InverseNormalizer(enable_0_to_9=True, overwrite_cache=True)
|
|
80
|
+
print("中文 TN (不去除儿化音,重新在线构图):\n\t{} => {}".format(zh_tn_text, zh_tn_model.normalize(zh_tn_text)))
|
|
81
|
+
print("中文ITN (小于10的单独数字也进行转换,重新在线构图):\n\t{} => {}\n".format(zh_itn_text, zh_itn_model.normalize(zh_itn_text)))
|
|
62
82
|
```
|
|
63
83
|
|
|
64
84
|
#### 1.2 Advanced Usage:
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
itn/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
itn/__main__.py,sha256=jFh8bEB_lC5y7ab9VMqAxWRaI8D-SpBSTiHfMJC1b10,65
|
|
3
3
|
itn/main.py,sha256=NnT9Sh3VTEI0sX_DO9IGVsXCWtZyfRbzj9Sj_6cBxqM,2610
|
|
4
|
-
itn/zh_itn_tagger.fst,sha256=
|
|
4
|
+
itn/zh_itn_tagger.fst,sha256=WUG3WqZ7ZbyqbbPvueFM-GEco96rsGNjx5ZDRg7USA8,1175402
|
|
5
5
|
itn/zh_itn_verbalizer.fst,sha256=pHXRUfzls2UmWwTmHHhYmBWMusIfWpU3I7IwxeRjn28,119018
|
|
6
6
|
itn/chinese/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
itn/chinese/inverse_normalizer.py,sha256=9GpVP7_BCBoCIpoZkPa8aq-n7M56GhY9l4mp3jUGwpM,3563
|
|
8
8
|
itn/chinese/data/date/dd.tsv,sha256=4KnAC3ETYcPwLtiyJjJPSyU0F0UQnvTNEu3kVAG1oII,806
|
|
9
9
|
itn/chinese/data/date/mm.tsv,sha256=lkWAizxrCwko42QGsLhZZUmjJ0FJw8Faii7xqHLkZec,126
|
|
10
10
|
itn/chinese/data/default/blacklist.tsv,sha256=kLgMYyQjmJvc-O-2nhOF2EfBxJgNmOjLhDtbKzHenDk,8
|
|
11
|
-
itn/chinese/data/default/whitelist.tsv,sha256=
|
|
11
|
+
itn/chinese/data/default/whitelist.tsv,sha256=WLnLWYcAYWQuZfEZAVJlGyDQi4C1oFXeXTa3be8kk-M,1686
|
|
12
12
|
itn/chinese/data/license_plate/province.tsv,sha256=8FGMiiTQgp-PWOG9SGzLJSyIgqlB2ZWsHXIKA4CheTw,124
|
|
13
13
|
itn/chinese/data/math/operator.tsv,sha256=_qGhDdskEaXRL4oKWy1lbeUWIG-ySpot9n23iu5sX9Q,47
|
|
14
14
|
itn/chinese/data/measure/units_en.tsv,sha256=hjkxNHc9g6EEnrbzQy32FqNFT8fkA9MAT6VBeeZ4TW0,1087
|
|
@@ -16,6 +16,7 @@ itn/chinese/data/measure/units_zh.tsv,sha256=4X-3EKTKOiR2vYZQrHWqBAZtogpG13eO4PO
|
|
|
16
16
|
itn/chinese/data/money/code.tsv,sha256=QXzDJD0QJm1FtsTtMIzI641ZSYReJfr7Q5ZRZYKbImM,2374
|
|
17
17
|
itn/chinese/data/money/symbol.tsv,sha256=5QxiR9VnB6pX2l3EKmbdbwLLGCJrDHEpym2DxqVXRxQ,1266
|
|
18
18
|
itn/chinese/data/number/digit.tsv,sha256=l-5ompNSHfBLhgWaTr-QqBh7iLN3PGty571UandT2Q4,126
|
|
19
|
+
itn/chinese/data/number/digit_zh.tsv,sha256=5MZabXiLvomGd0dMjHEjppbKnnIYOATZJvs9W9iQi3E,40
|
|
19
20
|
itn/chinese/data/number/dot.tsv,sha256=1xj5VPX4Qu0JiPycy8cTAqpsGAJJrbQwqab_TctCXqs,12
|
|
20
21
|
itn/chinese/data/number/sign.tsv,sha256=VnjOk140OULqin_tHv_nK15DJSTjvCO-E2hYnYYSp24,31
|
|
21
22
|
itn/chinese/data/number/special_dash.tsv,sha256=9zJdqG_rFu48lmeCxGLsEFOSoqUUjNVUNRtbHQ9L7Nk,661
|
|
@@ -32,7 +33,7 @@ itn/chinese/rules/date.py,sha256=8pB_S9BFKYd5rXGxzfjAcas-ecLM4dUnhNIsp_vZgI0,244
|
|
|
32
33
|
itn/chinese/rules/fraction.py,sha256=jGhKx91TtscqPFwDtqaI0zeMCAsCFA68KPCWBXtT030,2030
|
|
33
34
|
itn/chinese/rules/license_plate.py,sha256=z0bSp1RjQB_8p2FeKSgUMhYJ1CxO_3fP8pzcb75DOec,1567
|
|
34
35
|
itn/chinese/rules/math.py,sha256=A_iEaTmBg95M73aIPz_L7cGLe8ZMD2ODP33a6_esfoM,1263
|
|
35
|
-
itn/chinese/rules/measure.py,sha256=
|
|
36
|
+
itn/chinese/rules/measure.py,sha256=0ixwJ54RIJlCG0-dE4bOA9usHFRdHT7JHL6K2Bch9bs,4430
|
|
36
37
|
itn/chinese/rules/money.py,sha256=fqS28BjAdGY-jQGTh3SZbd7bA1_ylFznCaMW_0e4Gr8,2271
|
|
37
38
|
itn/chinese/rules/postprocessor.py,sha256=BZ1dpyaQJwxTIzsxmMrMbv5PuLbCza-163ERJ8ZC8MY,1208
|
|
38
39
|
itn/chinese/rules/time.py,sha256=m99PvGEnPZSXHiu3vY8S7PzzjMdypn61u2uz6hSrUM4,2033
|
|
@@ -42,9 +43,9 @@ itn/chinese/test/normalizer_test.py,sha256=a9nqt-is07zYOl3XDAhjUyNzBlwBe3qdaHtvT
|
|
|
42
43
|
itn/chinese/test/utils.py,sha256=aCZH5BL0dghGjemhVwfISBUxLFMG_ceMzwzuOb5ht28,1094
|
|
43
44
|
tn/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
44
45
|
tn/__main__.py,sha256=OUMsgyp8SWb7raJY_py61uM29j023yE5po95O9yinzk,64
|
|
45
|
-
tn/en_tn_tagger.fst,sha256=
|
|
46
|
-
tn/en_tn_verbalizer.fst,sha256=
|
|
47
|
-
tn/main.py,sha256=
|
|
46
|
+
tn/en_tn_tagger.fst,sha256=yYMCyIUBnfeq35yr6M0Bn_DSSs-iKoA3uLW4IbSbk-M,5248066
|
|
47
|
+
tn/en_tn_verbalizer.fst,sha256=DcK9hJao5KFpWSSVsV3BhJ1QIJfIo9OHU0ahc3YbSLQ,2121910
|
|
48
|
+
tn/main.py,sha256=ZQ1ZWOa-5YoU_PNDSt2P-f3RC79WUwT0UMqm4bulCIA,3587
|
|
48
49
|
tn/processor.py,sha256=CUmJ7B0OyweByf7U0yi2TYqBbEhhWTcqs03_0XhTosg,5012
|
|
49
50
|
tn/token_parser.py,sha256=nsTYzug-gq2HYnTJHja_HXntoRVX3gITQAlI9z8WvWU,4487
|
|
50
51
|
tn/utils.py,sha256=lJLuW2jkobgXCyNYl29zhtyb3B80CS7Pqz7zqHRVr4c,2792
|
|
@@ -110,7 +111,7 @@ tn/chinese/test/token_parser_test.py,sha256=8JcSqlvaYTZ46rZgMsfAVNmcYez6t0gonhnx
|
|
|
110
111
|
tn/chinese/test/utils.py,sha256=aCZH5BL0dghGjemhVwfISBUxLFMG_ceMzwzuOb5ht28,1094
|
|
111
112
|
tn/chinese/test/whitelist_test.py,sha256=oPB-7_g8l6zhAeH5fp7NlaRJYcDNz7VAOKwhCnebGdc,1003
|
|
112
113
|
tn/english/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
113
|
-
tn/english/normalizer.py,sha256=
|
|
114
|
+
tn/english/normalizer.py,sha256=91v9En8-6ishv0UPaLg1wpoLqFVoEBQUZBLtWlK_zKE,4157
|
|
114
115
|
tn/english/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
115
116
|
tn/english/data/suppletive.tsv,sha256=iih47clDISe35FR-p4Usu_coR3oQy1miXd4VsBJSsyA,1843
|
|
116
117
|
tn/english/data/address/__init__.py,sha256=EqFAHHjK7kJqR_FV8vBLddBJWhbVD8pREEfm8C5nSEE,623
|
|
@@ -170,7 +171,7 @@ tn/english/data/whitelist/asr_with_pc.tsv,sha256=wqeEeG4O742D2vroywzbstwmr-s6lGH
|
|
|
170
171
|
tn/english/data/whitelist/ipa_symbols.tsv,sha256=ChsK_JiztbsqNnFYNQ0xZ9QCFUxeTqRzm8vCkydQvl8,2532
|
|
171
172
|
tn/english/data/whitelist/lj_speech.tsv,sha256=-sZeHERreSBZGbLiJh0q_laYvXWG5mvMAUuXkYiHQdI,263
|
|
172
173
|
tn/english/data/whitelist/symbol.tsv,sha256=rIyi-7u3X-DoBslNDaAQghNVWlD6yLAgYS2nuGKQUJ4,240
|
|
173
|
-
tn/english/data/whitelist/tts.tsv,sha256=
|
|
174
|
+
tn/english/data/whitelist/tts.tsv,sha256=8qu9zewiYFiK-PQnVVEueF6fbTpV5D2-86iF05C3cIE,33157
|
|
174
175
|
tn/english/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
175
176
|
tn/english/rules/cardinal.py,sha256=w3HvKbq86mZjb3MhXc96D_Ajaem1raCHs0pCGvhQaRs,8424
|
|
176
177
|
tn/english/rules/date.py,sha256=QoUczkPwAeYanT41_8Qpi_FqvuSfvXX5LHdEgcsLkVA,13683
|
|
@@ -180,7 +181,7 @@ tn/english/rules/fraction.py,sha256=ltGhbd1Qeb-BsuVCPYq8cc__k0Xkkn4WBUiz6dFs8J8,
|
|
|
180
181
|
tn/english/rules/measure.py,sha256=DjQnq_9UXL-pHdqaHkp3oUv4qEhiGB_764YmUEq9v6w,14025
|
|
181
182
|
tn/english/rules/money.py,sha256=0hjQWUdI4wWsOVKkkBs5lvFsQaMIWOQcs6oOLBhQzDM,5457
|
|
182
183
|
tn/english/rules/ordinal.py,sha256=xFUaNvPx2rKDJz3TMiE2RKje6gcvcVImr3sXixWfOKU,3989
|
|
183
|
-
tn/english/rules/punctuation.py,sha256=
|
|
184
|
+
tn/english/rules/punctuation.py,sha256=Pno-BxVZrFVzNVu8X5f8EpoxMv4JOpBuJekBhM8fT5Y,3274
|
|
184
185
|
tn/english/rules/range.py,sha256=lEjLyFBJSCHnHlQBdrzhiUdNVIiwTQClPz4DNRqHnB4,5730
|
|
185
186
|
tn/english/rules/roman.py,sha256=pQFuSIjzWnMN-jiSuVqv3AxJEA9kA8s0NUgGpCCVbiU,6051
|
|
186
187
|
tn/english/rules/telephone.py,sha256=JkhHZU1O2h4a_W3QHVBY1lOQvq4Tys5JwAlL1Kkt8Pg,8275
|
|
@@ -204,9 +205,9 @@ tn/english/test/time_test.py,sha256=4E_PS-D5caTUZgrI-UL7q0aoqmtD8np7yeXUkGyc1Qo,
|
|
|
204
205
|
tn/english/test/utils.py,sha256=aCZH5BL0dghGjemhVwfISBUxLFMG_ceMzwzuOb5ht28,1094
|
|
205
206
|
tn/english/test/whitelist_test.py,sha256=fnlpnwiDgQWsl5ONZklWXEyLQoUSuwhdowcV7a8fXvw,1023
|
|
206
207
|
tn/english/test/word_test.py,sha256=ACguloXPl4Ttw8fj9F_wvr1coaQAoj_MLOJ74wyy-WY,954
|
|
207
|
-
WeTextProcessing-1.0.
|
|
208
|
-
WeTextProcessing-1.0.
|
|
209
|
-
WeTextProcessing-1.0.
|
|
210
|
-
WeTextProcessing-1.0.
|
|
211
|
-
WeTextProcessing-1.0.
|
|
212
|
-
WeTextProcessing-1.0.
|
|
208
|
+
WeTextProcessing-1.0.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
209
|
+
WeTextProcessing-1.0.3.dist-info/METADATA,sha256=gM1M2EyE0OQASspFF5zh_kP39uSUmSsfx6znL3P0_w4,7181
|
|
210
|
+
WeTextProcessing-1.0.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
211
|
+
WeTextProcessing-1.0.3.dist-info/entry_points.txt,sha256=iAd8tFSNA8AY5fUECPlk9KaDFC3ISvDjoKAZVsCWPjE,61
|
|
212
|
+
WeTextProcessing-1.0.3.dist-info/top_level.txt,sha256=6NasE_UheQezX9_0V3MbiOSnTQpvM_funMjv4wpMGgA,7
|
|
213
|
+
WeTextProcessing-1.0.3.dist-info/RECORD,,
|
itn/chinese/rules/measure.py
CHANGED
|
@@ -16,7 +16,7 @@ from itn.chinese.rules.cardinal import Cardinal
|
|
|
16
16
|
from tn.processor import Processor
|
|
17
17
|
from tn.utils import get_abs_path
|
|
18
18
|
|
|
19
|
-
from pynini import string_file, accep, cross
|
|
19
|
+
from pynini import string_file, accep, cross, union
|
|
20
20
|
from pynini.lib.pynutil import delete, insert, add_weight
|
|
21
21
|
|
|
22
22
|
|
|
@@ -36,6 +36,11 @@ class Measure(Processor):
|
|
|
36
36
|
get_abs_path('../itn/chinese/data/measure/units_zh.tsv'))
|
|
37
37
|
sign = string_file(
|
|
38
38
|
get_abs_path('../itn/chinese/data/number/sign.tsv')) # + -
|
|
39
|
+
digit = string_file(
|
|
40
|
+
get_abs_path('../itn/chinese/data/number/digit.tsv')) # 1 ~ 9
|
|
41
|
+
digit_zh = string_file(
|
|
42
|
+
get_abs_path('../itn/chinese/data/number/digit_zh.tsv')) # 1 ~ 9
|
|
43
|
+
addzero = insert('0')
|
|
39
44
|
to = cross('到', '~') | cross('到百分之', '~')
|
|
40
45
|
|
|
41
46
|
units = add_weight(
|
|
@@ -55,8 +60,35 @@ class Measure(Processor):
|
|
|
55
60
|
|
|
56
61
|
# 十千米每小时 => 10km/h, 十一到一百千米每小时 => 11~100km/h
|
|
57
62
|
measure = number + (to + number).ques + units
|
|
58
|
-
tagger = insert('value: "') + (measure | percent) + insert('"')
|
|
59
63
|
|
|
64
|
+
# XXX: 特殊case处理, ignore enable_standalone_number
|
|
65
|
+
# digit + union("百", "千", "万") + digit + unit
|
|
66
|
+
unit_sp_case1 = [
|
|
67
|
+
'年',
|
|
68
|
+
'月',
|
|
69
|
+
'个月',
|
|
70
|
+
'周',
|
|
71
|
+
'天',
|
|
72
|
+
'位',
|
|
73
|
+
'次',
|
|
74
|
+
'个',
|
|
75
|
+
'顿',
|
|
76
|
+
]
|
|
77
|
+
if self.enable_0_to_9:
|
|
78
|
+
measure_sp = add_weight(
|
|
79
|
+
((digit + delete('百') + add_weight(addzero**2, 1.0)) |
|
|
80
|
+
(digit + delete('千') + add_weight(addzero**3, 1.0)) |
|
|
81
|
+
(digit + delete('万') + add_weight(addzero**4, 1.0))) +
|
|
82
|
+
insert(' ') + digit + union(*unit_sp_case1), -0.5)
|
|
83
|
+
else:
|
|
84
|
+
measure_sp = add_weight(
|
|
85
|
+
((digit + delete('百') + add_weight(addzero**2, 1.0)) |
|
|
86
|
+
(digit + delete('千') + add_weight(addzero**3, 1.0)) |
|
|
87
|
+
(digit + delete('万') + add_weight(addzero**4, 1.0))) +
|
|
88
|
+
digit_zh + union(*unit_sp_case1), -0.5)
|
|
89
|
+
|
|
90
|
+
tagger = insert('value: "') + (measure | measure_sp
|
|
91
|
+
| percent) + insert('"')
|
|
60
92
|
# 每小时十千米 => 10km/h, 每小时三十到三百一十一千米 => 30~311km/h
|
|
61
93
|
tagger |= (insert('denominator: "') + delete('每') + units +
|
|
62
94
|
insert('" numerator: "') + measure + insert('"'))
|
itn/zh_itn_tagger.fst
CHANGED
|
Binary file
|
tn/en_tn_tagger.fst
CHANGED
|
Binary file
|
tn/en_tn_verbalizer.fst
CHANGED
|
Binary file
|
tn/english/normalizer.py
CHANGED
|
@@ -57,15 +57,25 @@ class Normalizer(Processor):
|
|
|
57
57
|
punct = add_weight(Punctuation().tagger, 2.00)
|
|
58
58
|
rang = add_weight(Range().tagger, 1.01)
|
|
59
59
|
# TODO(xcsong): add roman
|
|
60
|
-
tagger =
|
|
61
|
-
(cardinal
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
60
|
+
tagger = \
|
|
61
|
+
(cardinal
|
|
62
|
+
| ordinal
|
|
63
|
+
| word
|
|
64
|
+
| date
|
|
65
|
+
| decimal
|
|
66
|
+
| fraction
|
|
67
|
+
| time
|
|
68
|
+
| measure
|
|
69
|
+
| money
|
|
70
|
+
| telephone
|
|
71
|
+
| electronic
|
|
65
72
|
| whitelist
|
|
66
|
-
| rang
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
| rang
|
|
74
|
+
| punct
|
|
75
|
+
).optimize() + (punct.plus | self.DELETE_SPACE)
|
|
76
|
+
# delete the first and last space
|
|
77
|
+
self.tagger = (delete(' ').star + tagger.star) @ self.build_rule(
|
|
78
|
+
delete(' '), r='[EOS]')
|
|
69
79
|
|
|
70
80
|
def build_verbalizer(self):
|
|
71
81
|
cardinal = Cardinal().verbalizer
|
|
@@ -83,14 +93,20 @@ class Normalizer(Processor):
|
|
|
83
93
|
punct = Punctuation().verbalizer
|
|
84
94
|
rang = Range().verbalizer
|
|
85
95
|
verbalizer = \
|
|
86
|
-
(cardinal
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
96
|
+
(cardinal
|
|
97
|
+
| ordinal
|
|
98
|
+
| word
|
|
99
|
+
| date
|
|
100
|
+
| decimal
|
|
101
|
+
| fraction
|
|
102
|
+
| time
|
|
103
|
+
| measure
|
|
104
|
+
| money
|
|
90
105
|
| telephone
|
|
91
106
|
| electronic
|
|
92
107
|
| whitelist
|
|
93
108
|
| punct
|
|
94
|
-
| rang
|
|
109
|
+
| rang
|
|
110
|
+
).optimize() + (punct.plus | self.INSERT_SPACE)
|
|
95
111
|
self.verbalizer = verbalizer.star @ self.build_rule(delete(' '),
|
|
96
112
|
r='[EOS]')
|
tn/english/rules/punctuation.py
CHANGED
|
@@ -61,14 +61,15 @@ class Punctuation(Processor):
|
|
|
61
61
|
punct = closure(self.punct | cross('\\', '\\\\\\') | cross('"', '\\"'),
|
|
62
62
|
1)
|
|
63
63
|
|
|
64
|
-
emphasis = (
|
|
64
|
+
self.emphasis = (
|
|
65
65
|
accep("<") +
|
|
66
66
|
((
|
|
67
67
|
closure(self.NOT_SPACE - union("<", ">"), 1) + # noqa
|
|
68
68
|
closure(accep("/"), 0, 1)) # noqa
|
|
69
69
|
| (accep("/") + closure(self.NOT_SPACE - union("<", ">"), 1))) +
|
|
70
70
|
accep(">")) # noqa
|
|
71
|
-
punct = plurals._priority_union(emphasis, punct,
|
|
71
|
+
punct = plurals._priority_union(self.emphasis, punct,
|
|
72
|
+
closure(self.VCHAR))
|
|
72
73
|
|
|
73
74
|
self.graph = punct
|
|
74
75
|
final_graph = insert("v: \"") + add_weight(
|
|
@@ -78,7 +79,10 @@ class Punctuation(Processor):
|
|
|
78
79
|
|
|
79
80
|
def build_verbalizer(self):
|
|
80
81
|
punct = closure(
|
|
81
|
-
self.punct |
|
|
82
|
-
|
|
|
83
|
-
verbalizer = delete('v: "') +
|
|
82
|
+
self.punct | self.emphasis | cross('\\\\\\', '\\')
|
|
83
|
+
| cross('\\"', '"'), 1)
|
|
84
|
+
verbalizer = delete('v: "') + add_weight(accep(" "), -1.0).star \
|
|
85
|
+
+ punct \
|
|
86
|
+
+ add_weight(accep(" "), -1.0).star \
|
|
87
|
+
+ delete('"')
|
|
84
88
|
self.verbalizer = self.delete_tokens(verbalizer)
|
tn/main.py
CHANGED
|
@@ -73,9 +73,8 @@ def main():
|
|
|
73
73
|
full_to_half=str2bool(args.full_to_half),
|
|
74
74
|
tag_oov=str2bool(args.tag_oov))
|
|
75
75
|
elif args.language == "en":
|
|
76
|
-
normalizer = EnNormalizer(
|
|
77
|
-
|
|
78
|
-
overwrite_cache=args.overwrite_cache)
|
|
76
|
+
normalizer = EnNormalizer(cache_dir=args.cache_dir,
|
|
77
|
+
overwrite_cache=args.overwrite_cache)
|
|
79
78
|
|
|
80
79
|
if args.text:
|
|
81
80
|
print(normalizer.tag(args.text))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|