I was searching for a bible search algorithm a while ago, and I couldn't find one publicly posted, so I wrote my own. Those familiar with the bible know that it is expressed in this format:
- Book Chapter:Verse
- e.g., John 3:16
But of course one can also show multiple references together using a combination of dashes, semi-colons, and commas.
- John 4; James 1:2-8
(Entire chapter 4 of John, James 1 verses 2 through 8) - John 7:40-8:11
(John chapter 7 verse 40 through chapter 8 verse 11) - Ge 12:1-8; 15:1-6
(Genesis chapter 12 verse 1 through 8, chapter 15 verse 1 through 6)
So I was considering how I could parse this down. I wrote to a few sites who do search results according to these generally agreed-upon principles, but I got no reply. So I wrote my own and thought I would share it. It's written in PHP but could certainly be adapted to anything. It does not use OOP and could probably be improved upon, but I am not a programmer by nature, so I figured I would just post what I have.
There are a few functions that work together to do the job. I will post the first one here with an explanation. This function normalizes the input into something that the other functions can use.
This function is designed to be called with the raw input. Here is what it would show for the various inputs above:
Array ( [0] => John 4 [1] => James 1:2-8 )
Array ( [0] => John 7:40-8:11 )
Array ( [0] => Ge 12:1-8 [1] => Ge 15:1-6 )
In the next post I'll talk about the next step in processing the data, which is breaking out the ranges into a top-most range and a bottom-most range using the hyphens as guidelines.
In subsequent posts, I'll outline the procedure for converting the abbreviation into the full book name (e.g., Ge → Genesis) and actually pulling data from the database, which may look different for different people depending on the database in use, etc.
No comments:
Post a Comment