Most of the pep8 changes finished. Be careful, things may be horribly broken.
This commit is contained in:
@ -14,10 +14,10 @@ currentdir = os.path.dirname(
|
||||
os.path.abspath(
|
||||
inspect.getfile(
|
||||
inspect.currentframe()))))
|
||||
fenrirPath = os.path.dirname(currentdir)
|
||||
fenrir_path = os.path.dirname(currentdir)
|
||||
|
||||
|
||||
class punctuationManager():
|
||||
class PunctuationManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@ -44,105 +44,105 @@ class punctuationManager():
|
||||
def shutdown(self):
|
||||
pass
|
||||
|
||||
def removeUnused(self, text, currLevel=''):
|
||||
def remove_unused(self, text, curr_level=''):
|
||||
# dont translate dot and comma because they create a pause
|
||||
currAllPunctNone = self.allPunctNone.copy()
|
||||
for char in currLevel:
|
||||
curr_all_punct_none = self.allPunctNone.copy()
|
||||
for char in curr_level:
|
||||
try:
|
||||
del currAllPunctNone[ord(char)]
|
||||
del curr_all_punct_none[ord(char)]
|
||||
except Exception as e:
|
||||
pass
|
||||
return text.translate(currAllPunctNone)
|
||||
return text.translate(curr_all_punct_none)
|
||||
|
||||
def useCustomDict(self, text, customDict, seperator=''):
|
||||
resultText = str(text)
|
||||
def use_custom_dict(self, text, customDict, seperator=''):
|
||||
result_text = str(text)
|
||||
if customDict:
|
||||
for key, item in customDict.items():
|
||||
try:
|
||||
regexLbl = 'REGEX;'
|
||||
if key.upper().startswith(regexLbl) and (len(key) > len(regexLbl)):
|
||||
resultText = re.sub(
|
||||
str(key[len(regexLbl):]), seperator + str(item) + seperator, resultText)
|
||||
regex_lbl = 'REGEX;'
|
||||
if key.upper().startswith(regex_lbl) and (len(key) > len(regex_lbl)):
|
||||
result_text = re.sub(
|
||||
str(key[len(regex_lbl):]), seperator + str(item) + seperator, result_text)
|
||||
else:
|
||||
resultText = resultText.replace(
|
||||
result_text = result_text.replace(
|
||||
str(key), seperator + str(item) + seperator)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
"useCustomDict replace:'" +
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
"use_custom_dict replace:'" +
|
||||
key +
|
||||
"' with '" +
|
||||
item +
|
||||
"' failed:" +
|
||||
str(e),
|
||||
debug.debugLevel.ERROR,
|
||||
onAnyLevel=False)
|
||||
return resultText
|
||||
debug.DebugLevel.ERROR,
|
||||
on_any_level=False)
|
||||
return result_text
|
||||
|
||||
def usePunctuationDict(self, text, punctuationDict, punctuation):
|
||||
resultText = str(text)
|
||||
def use_punctuation_dict(self, text, punctuationDict, punctuation):
|
||||
result_text = str(text)
|
||||
|
||||
if punctuationDict and punctuation and punctuation != '':
|
||||
if ' ' in punctuation:
|
||||
resultText = resultText.replace(
|
||||
result_text = result_text.replace(
|
||||
' ', ' ' + punctuationDict[' '] + ' ')
|
||||
for key, item in punctuationDict.items():
|
||||
if (punctuation != '' and key in punctuation) and key not in ' ':
|
||||
if self.env['runtime']['settingsManager'].getSetting(
|
||||
if self.env['runtime']['SettingsManager'].get_setting(
|
||||
'general', 'respectPunctuationPause') and len(key) == 1 and key in "',.;:?!":
|
||||
resultText = resultText.replace(
|
||||
result_text = result_text.replace(
|
||||
str(key), ' ' + str(item) + str(key) + ' ')
|
||||
else:
|
||||
resultText = resultText.replace(
|
||||
result_text = result_text.replace(
|
||||
str(key), ' ' + str(item) + ' ')
|
||||
return resultText
|
||||
return result_text
|
||||
|
||||
def isPuctuation(self, char):
|
||||
def is_puctuation(self, char):
|
||||
return char in self.env['punctuation']['PUNCTDICT']
|
||||
|
||||
def proceedPunctuation(self, text, ignorePunctuation=False):
|
||||
if ignorePunctuation:
|
||||
def proceed_punctuation(self, text, ignore_punctuation=False):
|
||||
if ignore_punctuation:
|
||||
return text
|
||||
resultText = text
|
||||
resultText = self.useCustomDict(
|
||||
resultText, self.env['punctuation']['CUSTOMDICT'])
|
||||
if self.env['runtime']['settingsManager'].getSettingAsBool(
|
||||
result_text = text
|
||||
result_text = self.use_custom_dict(
|
||||
result_text, self.env['punctuation']['CUSTOMDICT'])
|
||||
if self.env['runtime']['SettingsManager'].get_setting_as_bool(
|
||||
'general', 'emoticons'):
|
||||
resultText = self.useCustomDict(
|
||||
resultText, self.env['punctuation']['EMOTICONDICT'], ' ')
|
||||
currPunctLevel = ''
|
||||
if self.env['runtime']['settingsManager'].getSetting(
|
||||
result_text = self.use_custom_dict(
|
||||
result_text, self.env['punctuation']['EMOTICONDICT'], ' ')
|
||||
curr_punct_level = ''
|
||||
if self.env['runtime']['SettingsManager'].get_setting(
|
||||
'general', 'punctuationLevel').lower() in self.env['punctuation']['LEVELDICT']:
|
||||
currPunctLevel = self.env['punctuation']['LEVELDICT'][self.env['runtime'][
|
||||
'settingsManager'].getSetting('general', 'punctuationLevel').lower()]
|
||||
curr_punct_level = self.env['punctuation']['LEVELDICT'][self.env['runtime'][
|
||||
'SettingsManager'].get_setting('general', 'punctuationLevel').lower()]
|
||||
else:
|
||||
currPunctLevel = string.punctuation + ' §'
|
||||
resultText = self.usePunctuationDict(
|
||||
resultText, self.env['punctuation']['PUNCTDICT'], currPunctLevel)
|
||||
resultText = self.removeUnused(resultText, currPunctLevel)
|
||||
return resultText
|
||||
curr_punct_level = string.punctuation + ' §'
|
||||
result_text = self.use_punctuation_dict(
|
||||
result_text, self.env['punctuation']['PUNCTDICT'], curr_punct_level)
|
||||
result_text = self.remove_unused(result_text, curr_punct_level)
|
||||
return result_text
|
||||
|
||||
def cyclePunctuation(self):
|
||||
punctList = list(self.env['punctuation']['LEVELDICT'].keys())
|
||||
def cycle_punctuation(self):
|
||||
punct_list = list(self.env['punctuation']['LEVELDICT'].keys())
|
||||
try:
|
||||
currIndex = punctList.index(
|
||||
self.env['runtime']['settingsManager'].getSetting(
|
||||
curr_index = punct_list.index(
|
||||
self.env['runtime']['SettingsManager'].get_setting(
|
||||
'general', 'punctuationLevel').lower()) # curr punctuation
|
||||
except Exception as e:
|
||||
return False
|
||||
currIndex += 1
|
||||
if currIndex >= len(punctList):
|
||||
currIndex = 0
|
||||
currLevel = punctList[currIndex]
|
||||
self.env['runtime']['settingsManager'].setSetting(
|
||||
'general', 'punctuationLevel', currLevel.lower())
|
||||
curr_index += 1
|
||||
if curr_index >= len(punct_list):
|
||||
curr_index = 0
|
||||
curr_level = punct_list[curr_index]
|
||||
self.env['runtime']['SettingsManager'].set_setting(
|
||||
'general', 'punctuationLevel', curr_level.lower())
|
||||
return True
|
||||
|
||||
def loadDicts(self, dictConfigPath=fenrirPath +
|
||||
def load_dicts(self, dictConfigPath=fenrir_path +
|
||||
'/../../config/punctuation/default.conf'):
|
||||
dictConfig = open(dictConfigPath, "r")
|
||||
currDictName = ''
|
||||
dict_config = open(dictConfigPath, "r")
|
||||
curr_dict_name = ''
|
||||
while (True):
|
||||
line = dictConfig.readline()
|
||||
line = dict_config.readline()
|
||||
if not line:
|
||||
break
|
||||
line = line.replace('\n', '')
|
||||
@ -153,24 +153,24 @@ class punctuationManager():
|
||||
continue
|
||||
if line.replace(" ", "").upper().startswith("[") and \
|
||||
line.replace(" ", "").upper().endswith("DICT]"):
|
||||
currDictName = line[line.find(
|
||||
curr_dict_name = line[line.find(
|
||||
'[') + 1:line.upper().find('DICT]') + 4].upper()
|
||||
else:
|
||||
if currDictName == '':
|
||||
if curr_dict_name == '':
|
||||
continue
|
||||
if ":===:" not in line:
|
||||
continue
|
||||
sepLine = line.split(':===:')
|
||||
if len(sepLine) == 1:
|
||||
sepLine.append('')
|
||||
elif len(sepLine) < 1:
|
||||
sep_line = line.split(':===:')
|
||||
if len(sep_line) == 1:
|
||||
sep_line.append('')
|
||||
elif len(sep_line) < 1:
|
||||
continue
|
||||
elif len(sepLine) > 2:
|
||||
sepLine[1] = ':===:'
|
||||
self.env['punctuation'][currDictName][sepLine[0]] = sepLine[1]
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
"Punctuation: " + currDictName + '.' + str(
|
||||
sepLine[0]) + ' :' + sepLine[1],
|
||||
debug.debugLevel.INFO,
|
||||
onAnyLevel=True)
|
||||
dictConfig.close()
|
||||
elif len(sep_line) > 2:
|
||||
sep_line[1] = ':===:'
|
||||
self.env['punctuation'][curr_dict_name][sep_line[0]] = sep_line[1]
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
"Punctuation: " + curr_dict_name + '.' + str(
|
||||
sep_line[0]) + ' :' + sep_line[1],
|
||||
debug.DebugLevel.INFO,
|
||||
on_any_level=True)
|
||||
dict_config.close()
|
||||
|
Reference in New Issue
Block a user