In 1899, the Ladies of the Trinity Church (Claremont, New Hampshire, USA) compiled a cookbook, that includes this contribution by Mrs L.M. Dow:
4 1/2 cups 1st Kings 4:22
1 1/2 cups Judges 5:25
2 cups Jeremiah 6:20
2 cups 1st Samuel 30:12
2 cups Nahum 3:12
1 cup Numbers 17:8
1/2 cup Judges 4:19
2 tablespoons of 1st Samuel 14:25
1 pinch of Leviticus 2:13
2 teaspoons of Amos 4:5
6 teaspoons Jeremiah 17:11
The first line calls for 4 1/2 cups of flour, because the King James version of the Bible, book The First Book of the Kings, chapter 4, verse 22 reads:
And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal.
The thirteenth word in this verse is flour, with words consisting of the longest possible sequence of letters (so that Solomon's consists of two words: Solomon and s).
In the same way, the other lines of the recipe refer respectively to the ingredients butter, sugar, raisins, figs, almonds, milk, honey, salt, leaven, and eggs. No baking instructions are given.
The Bible is a collection of several shorter books that were written independently of one another and over different periods, and were only compiled later. Each book has a unique title.
From the early thirteenth century onwards, all these books were further divided into chapters, each approximately one page long. Since the mid-sixteenth century, each chapter has been further divided into verses consisting of a few short lines or sentences. The chapters within a book are numbered consecutively, starting from 1. The verses within a chapter are also numbered consecutively, starting from 1. The usual way to refer to a Bible verse is by the title of the book, the chapter number, a colon and the verse number. For example, Genesis 3:5 refers to a passage from the Book of Genesis, chapter 3, verse 5.
We work with Bible files that contain a collection of verses from the Bible. A Bible file uses the following format (bible.txt):
# The First Book of Moses: Called Genesis 1:1 In the beginning God created the heaven and the earth. 1:2 And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. 1:3 And God said, Let there be light: and there was light. # The First Book of Samuel 14:25 And all they of the land came to a wood; and there was honey upon the ground. 30:12 And they gave him a piece of a cake of figs, and two clusters of raisins: and when he had eaten, his spirit came again to him: for he had eaten no bread, nor drunk any water, three days and three nights. # The First Book of the Kings 4:22 And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal,
The file consists of several paragraphs, each separated from the next by one or more blank lines. A blank line contains only whitespace characters (spaces and tabs). A paragraph consists of one or more non-blank lines. We distinguish between two types of paragraphs:
a paragraph that starts with a hash symbol (#) always consists of a single line; the hash symbol is followed by the title of a Bible book; there may be extra spaces at the beginning and end of the title, but these are not part of the title itself
each other paragraph describes a verse; a verse starts with chapter:verse, where chapter is the chapter number and verse is the verse number; this is followed by a space and the text of the verse, which may span multiple lines
All verses in a Bible file that follow the title of a book, belong to that book.
Your task:
Write a function read_paragraphs that takes the location (str) of a Bible file. The function must return a list (list) containing the paragraphs (str) from the file, listed in the order in which they appear in the file. Whitespace characters (spaces and tabs) at the start and end of each line of a paragraph must be removed, and the lines of a paragraph must be concatenated with a single space between each line. We call the result returned by this function the sequence of paragraphs in the Bible file.
Write a function read_bible that takes a sequences (list) of paragraphs (str) in a Bible file. The function must return a dictionary (dict) that maps each book title (str) in the file onto a dictionary (dict) that, for each verse in the book, maps the chapter and verse number (str; format: chapter:verse) onto the text (str) of the verse. We call the result returned by this function the index of the Bible file.
Write a function verse that takes four arguments: i) the index (dict) of a Bible file, ii) the title (str) of a book from the Bible file, iii) the number (int) of a chapter in the book, and iv) the number (int) of a verse in the chapter. The function must return the text (str) of the verse.
Write a function extract_words that takes a text (str). The function must return a list (list) containing the words (str) from the text, where words consist of the longest possible sequence of letters.
Write a function word that takes five arguments: i) the index (dict) of a Bible file, ii) the title (str) of a book from the Bible file, iii) the number (int) of a chapter in the book, iv) the number (int) of a verse in the chapter, and v) the number of a word $$w$$ in the text of the verse. Words in a text consist of the longest possible sequence of letters and are numbered consecutively starting from 1. The function must return the word $$w$$ (str).
In this interactive session, we assume the current directory contains the text file bible.txt.
>>> paragraphs = read_paragraphs('bible.txt')
>>> paragraphs
['# The First Book of Moses: Called Genesis', '1:1 In the beginning God created the heaven and the earth.', '1:2 And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.', '1:3 And God said, Let there be light: and there was light.', '# The First Book of Samuel', '14:25 And all they of the land came to a wood; and there was honey upon the ground.', '30:12 And they gave him a piece of a cake of figs, and two clusters of raisins: and when he had eaten, his spirit came again to him: for he had eaten no bread, nor drunk any water, three days and three nights.', '# The First Book of the Kings', '4:22 And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal,']
>>> bible = read_bible(paragraphs)
>>> bible
{'The First Book of Moses: Called Genesis': {'1:1': 'In the beginning God created the heaven and the earth.', '1:2': 'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.', '1:3': 'And God said, Let there be light: and there was light.'}, 'The First Book of Samuel': {'14:25': 'And all they of the land came to a wood; and there was honey upon the ground.', '30:12': 'And they gave him a piece of a cake of figs, and two clusters of raisins: and when he had eaten, his spirit came again to him: for he had eaten no bread, nor drunk any water, three days and three nights.'}, 'The First Book of the Kings': {'4:22': 'And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal,'}}
>>> verse(bible, 'The First Book of Moses: Called Genesis', 1, 1)
'In the beginning God created the heaven and the earth.'
>>> verse(bible, 'The First Book of the Kings', 4, 22)
'And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal,'
>>> verse(bible, 'The First Book of Samuel', 30, 12)
'And they gave him a piece of a cake of figs, and two clusters of raisins: and when he had eaten, his spirit came again to him: for he had eaten no bread, nor drunk any water, three days and three nights.'
>>> verse(bible, 'The First Book of Samuel', 14, 25)
'And all they of the land came to a wood; and there was honey upon the ground.'
>>> extract_words('In the beginning God created the heaven and the earth.')
['In', 'the', 'beginning', 'God', 'created', 'the', 'heaven', 'and', 'the', 'earth']
>>> extract_words('And Solomon’s provision for one day was thirty measures of fine flour, and threescore measures of meal,')
['And', 'Solomon', 's', 'provision', 'for', 'one', 'day', 'was', 'thirty', 'measures', 'of', 'fine', 'flour', 'and', 'threescore', 'measures', 'of', 'meal']
>>> extract_words('And they gave him a piece of a cake of figs, and two clusters of raisins: and when he had eaten, his spirit came again to him: for he had eaten no bread, nor drunk any water, three days and three nights.')
['And', 'they', 'gave', 'him', 'a', 'piece', 'of', 'a', 'cake', 'of', 'figs', 'and', 'two', 'clusters', 'of', 'raisins', 'and', 'when', 'he', 'had', 'eaten', 'his', 'spirit', 'came', 'again', 'to', 'him', 'for', 'he', 'had', 'eaten', 'no', 'bread', 'nor', 'drunk', 'any', 'water', 'three', 'days', 'and', 'three', 'nights']
>>> extract_words('And all they of the land came to a wood; and there was honey upon the ground.')
['And', 'all', 'they', 'of', 'the', 'land', 'came', 'to', 'a', 'wood', 'and', 'there', 'was', 'honey', 'upon', 'the', 'ground']
>>> word(bible, 'The First Book of Moses: Called Genesis', 1, 1, 10)
'earth'
>>> word(bible, 'The First Book of the Kings', 4, 22, 13)
'flour'
>>> word(bible, 'The First Book of Samuel', 30, 12, 16)
'raisins'
>>> word(bible, 'The First Book of Samuel', 14, 25, 14)
'honey'