Replace skipped punctuation with space. There's a setting in general, on by default, that will revert to old behavior if you replace it with false.
This commit is contained in:
@ -49,11 +49,38 @@ class PunctuationManager:
|
|||||||
def remove_unused(self, text, curr_level=""):
|
def remove_unused(self, text, curr_level=""):
|
||||||
# dont translate dot and comma because they create a pause
|
# dont translate dot and comma because they create a pause
|
||||||
curr_all_punct_none = self.allPunctNone.copy()
|
curr_all_punct_none = self.allPunctNone.copy()
|
||||||
|
|
||||||
|
# Check if we should replace undefined punctuation with spaces
|
||||||
|
replace_with_space = self.env["runtime"]["SettingsManager"].get_setting_as_bool(
|
||||||
|
"general", "replaceUndefinedPunctuationWithSpace"
|
||||||
|
)
|
||||||
|
|
||||||
|
# If the setting is disabled, use the old behavior (remove completely)
|
||||||
|
if not replace_with_space:
|
||||||
|
# Create a map that removes undefined punctuation instead of replacing with spaces
|
||||||
|
curr_all_punct_none = dict.fromkeys(
|
||||||
|
map(ord, string.punctuation + "§ "), None
|
||||||
|
)
|
||||||
|
# Restore the pause-important characters
|
||||||
|
for char in [
|
||||||
|
ord("'"),
|
||||||
|
ord("."),
|
||||||
|
ord(","),
|
||||||
|
ord(";"),
|
||||||
|
ord(":"),
|
||||||
|
ord("?"),
|
||||||
|
ord("!"),
|
||||||
|
ord("-"),
|
||||||
|
]:
|
||||||
|
curr_all_punct_none[char] = chr(char)
|
||||||
|
|
||||||
|
# Remove characters that are defined in the current punctuation level
|
||||||
for char in curr_level:
|
for char in curr_level:
|
||||||
try:
|
try:
|
||||||
del curr_all_punct_none[ord(char)]
|
del curr_all_punct_none[ord(char)]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return text.translate(curr_all_punct_none)
|
return text.translate(curr_all_punct_none)
|
||||||
|
|
||||||
def use_custom_dict(self, text, customDict, seperator=""):
|
def use_custom_dict(self, text, customDict, seperator=""):
|
||||||
|
@ -50,6 +50,7 @@ settings_data = {
|
|||||||
"punctuationProfile": "default",
|
"punctuationProfile": "default",
|
||||||
"punctuationLevel": "some",
|
"punctuationLevel": "some",
|
||||||
"respectPunctuationPause": True,
|
"respectPunctuationPause": True,
|
||||||
|
"replaceUndefinedPunctuationWithSpace": True,
|
||||||
"newLinePause": True,
|
"newLinePause": True,
|
||||||
"numberOfClipboards": 10,
|
"numberOfClipboards": 10,
|
||||||
"emoticons": True,
|
"emoticons": True,
|
||||||
|
Reference in New Issue
Block a user