add headLineManager

This commit is contained in:
chrys 2017-11-06 23:00:31 +01:00
parent c7b2484cb2
commit e5a69c7a30
4 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,45 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
import re
class headLineManager():
def __init__(self):
self.regExSingle = re.compile(r'(([^\w\s])\2{5,})')
self.regExDouble = re.compile(r'([^\w\s]{2,}){5,}')
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def replaceHeadLines(self, text):
result = ''
newText = ''
lastPos = 0
for match in self.regExDouble.finditer(text):
span = match.span()
newText += text[lastPos:span[0]]
numberOfChars = len(text[span[0]:span[1]])
name = text[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
newText += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
newText += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
newText += ' ' + text[lastPos:]
lastPos = 0
for match in self.regExSingle.finditer(newText):
span = match.span()
result += text[lastPos:span[0]]
numberOfChars = len(newText[span[0]:span[1]])
name = newText[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
result += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
result += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
result += ' ' + newText[lastPos:]
return result

View File

@ -92,9 +92,11 @@ class outputManager():
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
s = time.time()
text = self.env['runtime']['headLineManager'].replaceHeadLines(text)
text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation)
text = text.replace('\n',' , ')
print(time.time() -s)
self.env['runtime']['speechDriver'].speak(text)
self.env['runtime']['debug'].writeDebugOut("Speak: "+ text,debug.debugLevel.INFO)
except Exception as e:

View File

@ -21,6 +21,7 @@ from core import punctuationManager
from core import cursorManager
from core import applicationManager
from core import helpManager
from core import headLineManager
from core import environment
from core import inputData
from core.settingsData import settingsData
@ -344,6 +345,8 @@ class settingsManager():
environment['runtime']['applicationManager'].initialize(environment)
environment['runtime']['helpManager'] = helpManager.helpManager()
environment['runtime']['helpManager'].initialize(environment)
environment['runtime']['headLineManager'] = headLineManager.headLineManager()
environment['runtime']['headLineManager'].initialize(environment)
if environment['runtime']['screenManager'] == None:
environment['runtime']['screenManager'] = screenManager.screenManager()
environment['runtime']['screenManager'].initialize(environment)

View File

@ -10,6 +10,7 @@ import string
from select import select
from select import epoll
import select
import re
def removeNonprintable(text):
# Get the difference of all ASCII characters from the set of printable characters
@ -80,3 +81,37 @@ new = ((0,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,0,0),(1,1,0,0),(1,
trackHighlights(old,new,t,5)
'''
class headLineManipulation:
def __init__(self):
self.regExSingle = re.compile(r'(([^\w\s])\2{5,})')
self.regExDouble = re.compile(r'([^\w\s]{2,}){5,}')
def replaceHeadLines(self, text):
result = ''
newText = ''
lastPos = 0
for match in self.regExDouble.finditer(text):
span = match.span()
newText += text[lastPos:span[0]]
numberOfChars = len(text[span[0]:span[1]])
name = text[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
newText += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
newText += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
newText += ' ' + text[lastPos:]
lastPos = 0
for match in self.regExSingle.finditer(newText):
span = match.span()
result += text[lastPos:span[0]]
numberOfChars = len(newText[span[0]:span[1]])
name = newText[span[0]:span[1]][:2]
if name.strip(name[0]) == '':
result += ' ' + str(numberOfChars) + ' ' + name[0] + ' '
else:
result += ' ' + str(int(numberOfChars / 2)) + ' ' + name + ' '
lastPos = span[1]
result += ' ' + newText[lastPos:]
return result