Script to modify Bible texts (accessibility) [closed]

9

I'm not a programmer. I look for accessibility features because of my low vision.

I am trying to develop a workflow that locates in the document biblical texts in the pattern "John 3:16" and transform it into "John, chapter 3, verse 16". The idea is to make a screen reader pronounce this information more comprehensively.

In reality, I do not need this feature, but a friend with a much more limited vision than mine needs. As he is going to do a special Bible course, I want to adapt the material, which is quite extensive, for him.

My platform is iOS and I use an app called Editorial that allows Python scripts to run.

If anyone can help, I will be very grateful. The idea is to make this flow available to other people with a visual impairment.

    
asked by anonymous 11.12.2015 / 17:14

2 answers

3

Using :

import re
pattern = re.compile(r"(?P<nome>[^\s]+) (?P<capitulo>[^:]+?):(?P<versiculo>[^\s]+)")
s = "João 3:16"
m = pattern.search(s)
print m.group('nome') + ", capítulo " + m.group('capitulo') + ", versículo " + m.group('versiculo')
  

John, chapter 3, verse 16

IdeOne

    
11.12.2015 / 18:08
2

Here's a script in Python 3.1 that does what you need, it can be improved, but it works fine.

I tried to explain how it works in the comments, if you do not understand it down here I'll improve the explanation. If you have something wrong, let me know as well that I'll fix it.

import re #Importa o módulo de regex

original = "João 3:16" #Entrada do script

index = re.search('\d', original).start() #Define index como a posição que a regex encontrar o primeiro dígito

nome = original[: index - 1] #Captura a string até o primeiro dígito (-1 serve para remover o espaço)
cap = original[index : re.search(':', original).start()] #Obtém o número do capítulo - pega da string desde o primeiro dígito (index) até antes de ':' 
ver = original[re.search(':', original).start() + 1: ] #Obtém o número do versículo - uma posição depois de ':' até o final

final = "{nome}, capítulo {capitulo}, versículo {versiculo}".format(nome = nome, capitulo = cap, versiculo = ver)

print(final)
    
11.12.2015 / 18:02