Script for modifying Bible texts (accessibility)

Asked

Viewed 208 times

9

I’m not a programmer. I research accessibility features based on my low vision.

I am trying to develop a workflow that locates in the Bible texts standard "John 3:16" and transforms it into "John, chapter 3, verse 16". The idea is to make a screen reader pronounce this information in a more understandable way.

Actually, I don’t need this resource, but a friend with a much more limited vision than I need. As he will take a special Bible course, I want to adapt the material, which is quite extensive, for him.

My platform is iOS and use in it an app, called Editorial, which allows the execution of Python scripts.

If anyone can help I would be very grateful. The idea is to make this flow available to other visually impaired people.

  • 2

    Hi guys. I’m sorry for the lack of precision, if that was the case. But the app I use allows you to use both ways, that is, a full python script or an individual "find & replace" stream. Whichever is more productive. Grateful from now on.

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

2

Here is a Python 3.1 script that does what you need, it can be improved, but so it works well.

I tried to explain how it works in the comments, if you can not understand comment here below that I am improving the explanation. If there’s something wrong let me know 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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.