Update punctuationManager.py
This commit is contained in:
parent
7c92a3171d
commit
0cb7ea4410
@ -11,5 +11,46 @@ class punctuationManager():
|
|||||||
pass
|
pass
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
|
self.punctuation = {
|
||||||
|
'currLevel':'1',
|
||||||
|
'levels':{
|
||||||
|
'1':',',
|
||||||
|
'2':'.',
|
||||||
|
'3':'.,',
|
||||||
|
},
|
||||||
|
'punctuationDict':{
|
||||||
|
'.':'punkt',
|
||||||
|
',':'komma'
|
||||||
|
},
|
||||||
|
'customDict':{
|
||||||
|
'chrys':'awsome',
|
||||||
|
'cool':'mr chrys'
|
||||||
|
}
|
||||||
|
}
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
def removeUnused(self, text):
|
||||||
|
resultText = text.translate(text.maketrans(string.punctuation, ' '*len(string.punctuation)))
|
||||||
|
return resultText
|
||||||
|
def useCustomDict(self, text, customDict):
|
||||||
|
resultText = text
|
||||||
|
for key,item in customDict.items():
|
||||||
|
resultText = resultText.replace(str(key),str(item))
|
||||||
|
return resultText
|
||||||
|
def usePunctuationDict(self, text, punctuationDict, punctuation):
|
||||||
|
resultText = str(text)
|
||||||
|
for key,item in punctuationDict.items():
|
||||||
|
if key in punctuation:
|
||||||
|
resultText = resultText.replace(str(key),' ' +str(item) +' ')
|
||||||
|
return resultText
|
||||||
|
|
||||||
|
def proceedPunctuation(self, text, ignoreLevel=False):
|
||||||
|
resultText = self.useCustomDict(text, self.punctuation['customDict'])
|
||||||
|
currPunctLevel = ''
|
||||||
|
if not ignoreLevel:
|
||||||
|
currPunctLevel = self.punctuation['levels'][self.punctuation['currLevel']]
|
||||||
|
else:
|
||||||
|
currPunctLevel = string.punctuation
|
||||||
|
resultText = self.usePunctuationDict(resultText, self.punctuation['punctuationDict'], currPunctLevel)
|
||||||
|
resultText = self.removeUnused(resultText)
|
||||||
|
return resultText
|
||||||
|
Loading…
Reference in New Issue
Block a user