Skip to content

Commit c9afbcc

Browse files
committed
Added new condExp to skip speech chunks without numbers, optimized symbolExp with Unicode currency block and other scattered symbols, moved condExp and symbolExp out of config loader
1 parent 7527a08 commit c9afbcc

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

addon/globalPlugins/numberProcessing.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@
2323
addonHandler.initTranslation()
2424

2525
DEBUG = False
26+
# see https://www.currencycalc.com/symbols
2627
CURRENCY_SYMBOLS = (
2728
"$",
29+
"£",
30+
"¥",
31+
"¤",
2832
"💵",
29-
"€",
3033
"💶",
31-
"£",
3234
"💷",
33-
"¥",
3435
"💴",
35-
"₩",
36-
"₫"
36+
"﷼",
37+
"৳",
38+
"៛",
39+
"฿",
40+
"\\u20a0-\\u20cf" # Unicode currency block
3741
)
3842
confspec = {
3943
"autoEnable": "boolean(default=false)",
4044
"userMinLen": "integer(default=2)",
4145
}
4246
config.conf.spec["numberProcessing"] = confspec
47+
condExp = re.compile(r"\d")
48+
symbolExp = re.compile(r"([%s])?(\s*)?(\d+([,.]\d+)*)"%''.join(CURRENCY_SYMBOLS))
4349
profileStatus = {}
4450

4551
class Status(Enum):
@@ -55,13 +61,11 @@ def debugLog(message):
5561

5662
# (re)load config
5763
def loadConfig():
58-
global myConf, digitExp, symbolExp, curProfile
64+
global myConf, digitExp, curProfile
5965
myConf = config.conf["numberProcessing"]
6066
autoEnable = myConf["autoEnable"]
6167
userMinLen = myConf["userMinLen"]
62-
digitExp = re.compile(r'\d{%s,}'%userMinLen)
63-
symbols = ''.join(CURRENCY_SYMBOLS)
64-
symbolExp = re.compile(r'([%s])?(\s*)?(\d+([,.]\d+)?)'%symbols)
68+
digitExp = re.compile(r"\d{%s,}"%userMinLen)
6569
curProfile = config.conf.profiles[-1].name
6670
# adjust status for current profile
6771
if autoEnable:
@@ -78,7 +82,7 @@ def filter_numberProcessing(speechSequence):
7882
debugLog("Initial speech sequence: %s"%speechSequence)
7983
newSpeechSequence = []
8084
for item in speechSequence:
81-
if not isinstance(item, str):
85+
if not isinstance(item, str) or not condExp.search(item):
8286
newSpeechSequence.append(item)
8387
continue
8488
debugLog("Initial item: %s"%item)

0 commit comments

Comments
 (0)