improve punctuation manager for pause
This commit is contained in:
parent
bf7598723a
commit
f09fe39b61
@ -14,17 +14,21 @@ class punctuationManager():
|
|||||||
self.env = environment
|
self.env = environment
|
||||||
self.allPunctNone = dict.fromkeys(map(ord, string.punctuation +"§"), ' ')
|
self.allPunctNone = dict.fromkeys(map(ord, string.punctuation +"§"), ' ')
|
||||||
# replace with None:
|
# replace with None:
|
||||||
# grave, apostrophe
|
# dot, comma, grave, apostrophe
|
||||||
for char in [ord('`'),ord("'")]:
|
for char in [ord('.'),ord(','),ord('`'),ord("'")]:
|
||||||
self.allPunctNone[char] = None
|
self.allPunctNone[char] = None
|
||||||
# dont translate dot and comma because they create a pause
|
|
||||||
for char in [ord('.'),ord(',')]:
|
|
||||||
del self.allPunctNone[char]
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
def removeUnused(self, text):
|
def removeUnused(self, text, currLevel = ''):
|
||||||
return text.translate(self.allPunctNone)
|
# dont translate dot and comma because they create a pause
|
||||||
|
currAllPunctNone = self.allPunctNone.copy()
|
||||||
|
for char in currLevel:
|
||||||
|
try:
|
||||||
|
del currAllPunctNone[ord(char)]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return text.translate(currAllPunctNone)
|
||||||
|
|
||||||
def useCustomDict(self, text, customDict):
|
def useCustomDict(self, text, customDict):
|
||||||
resultText = str(text)
|
resultText = str(text)
|
||||||
@ -32,6 +36,7 @@ class punctuationManager():
|
|||||||
for key,item in customDict.items():
|
for key,item in customDict.items():
|
||||||
resultText = resultText.replace(str(key),str(item))
|
resultText = resultText.replace(str(key),str(item))
|
||||||
return resultText
|
return resultText
|
||||||
|
|
||||||
def usePunctuationDict(self, text, punctuationDict, punctuation):
|
def usePunctuationDict(self, text, punctuationDict, punctuation):
|
||||||
resultText = str(text)
|
resultText = str(text)
|
||||||
|
|
||||||
@ -52,7 +57,7 @@ class punctuationManager():
|
|||||||
else:
|
else:
|
||||||
currPunctLevel = string.punctuation
|
currPunctLevel = string.punctuation
|
||||||
resultText = self.usePunctuationDict(resultText, self.env['punctuation']['PUNCTDICT'], currPunctLevel)
|
resultText = self.usePunctuationDict(resultText, self.env['punctuation']['PUNCTDICT'], currPunctLevel)
|
||||||
resultText = self.removeUnused(resultText)
|
resultText = self.removeUnused(resultText, currPunctLevel)
|
||||||
return resultText
|
return resultText
|
||||||
|
|
||||||
def cyclePunctuation(self):
|
def cyclePunctuation(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user