[Tutor] Parsing Bible verses

W W srilyk at gmail.com
Fri May 22 00:47:46 CEST 2009


On Thu, May 21, 2009 at 4:26 PM, Eduardo Vieira <eduardo.susan at gmail.com>wrote:

> Hello, I'm planning to create a script to read a certain file, find
> the line that contains Bible references and then use that to query a
> bible database in order to print the verses in another file.
> I will be looking for lines like these:
> Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23
>
> So, references in different chapters are separated by a semicolon. My
> main challenge would be make the program guess that 10:12 refers to
> the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
> that will take more than Regex and I never studied anything about
> parser tools, really.
>
> Any suggestion how I should approach this?
>

Actually, a regex probably wouldn't be too far off. If you're comfortable
working with them it may even be a good thing...
Will the line always begin with "Lesson text:"? If so, that makes it a lot
easier. Something like:

for line in file:
    if line starts with "Lesson text":
        skip "lesson text"
        book = first word(s)
        verse[book] = list of references

that's a really basic flow of logic, but it's probably how I'd do it.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090521/f8974467/attachment.htm>


More information about the Tutor mailing list