2016-09-22 08:45:05 -04:00
|
|
|
#!/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
|
|
|
|
2016-09-22 16:42:14 -04:00
|
|
|
import string
|
2016-09-22 08:45:05 -04:00
|
|
|
from core import debug
|
|
|
|
|
2016-09-22 08:46:34 -04:00
|
|
|
class punctuationManager():
|
2016-09-22 08:45:05 -04:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
def initialize(self, environment):
|
|
|
|
self.env = environment
|
2016-09-22 10:06:59 -04:00
|
|
|
self.punctuation = {
|
2016-09-22 16:42:14 -04:00
|
|
|
'currLevel':'3',
|
2016-09-22 10:06:59 -04:00
|
|
|
'levels':{
|
|
|
|
'1':',',
|
|
|
|
'2':'.',
|
|
|
|
'3':'.,',
|
|
|
|
},
|
|
|
|
'punctuationDict':{
|
|
|
|
'.':'punkt',
|
|
|
|
',':'komma'
|
|
|
|
},
|
|
|
|
'customDict':{
|
|
|
|
'chrys':'awsome',
|
|
|
|
'cool':'mr chrys'
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 08:45:05 -04:00
|
|
|
def shutdown(self):
|
|
|
|
pass
|
2016-09-22 10:06:59 -04:00
|
|
|
def removeUnused(self, text):
|
2016-09-22 10:50:26 -04:00
|
|
|
return text.translate(text.maketrans(string.punctuation, ' '*len(string.punctuation)))
|
2016-09-22 10:06:59 -04:00
|
|
|
def useCustomDict(self, text, customDict):
|
2016-09-22 10:53:31 -04:00
|
|
|
resultText = str(text)
|
2016-09-22 10:50:26 -04:00
|
|
|
if customDict:
|
|
|
|
for key,item in customDict.items():
|
|
|
|
resultText = resultText.replace(str(key),str(item))
|
2016-09-22 10:06:59 -04:00
|
|
|
return resultText
|
|
|
|
def usePunctuationDict(self, text, punctuationDict, punctuation):
|
|
|
|
resultText = str(text)
|
2016-09-22 16:42:14 -04:00
|
|
|
|
|
|
|
if punctuationDict and punctuation and punctuation != '':
|
2016-09-22 10:50:26 -04:00
|
|
|
for key,item in punctuationDict.items():
|
|
|
|
if key in punctuation:
|
|
|
|
resultText = resultText.replace(str(key),' ' +str(item) +' ')
|
2016-09-22 16:42:14 -04:00
|
|
|
|
2016-09-22 10:06:59 -04:00
|
|
|
return resultText
|
|
|
|
|
2016-09-22 16:42:14 -04:00
|
|
|
def proceedPunctuation(self, text, ignorePunctuation=False):
|
2016-09-22 10:06:59 -04:00
|
|
|
resultText = self.useCustomDict(text, self.punctuation['customDict'])
|
|
|
|
currPunctLevel = ''
|
2016-09-22 16:42:14 -04:00
|
|
|
if not ignorePunctuation and self.punctuation['currLevel'] in self.punctuation['levels']:
|
2016-09-22 10:06:59 -04:00
|
|
|
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
|