python-scriptures
Advanced tools
| from .base import InvalidReferenceException |
| from __future__ import unicode_literals | ||
| import re | ||
| class InvalidReferenceException(Exception): | ||
| """ | ||
| Invalid Reference Exception | ||
| """ | ||
| pass | ||
| class Text: | ||
| def __init__(self): | ||
| # Check for books | ||
| if hasattr(self, 'books'): | ||
| # make sure it is a dictionary | ||
| if not isinstance(self.books, dict): | ||
| raise Exception('"books" should be a dictionary, who\'s values are four valued tuples (Book Name, Abbreviation, Regex, [ch1_verse_count, ch2_verse_count, ...])') | ||
| # set the regex instance variables | ||
| self.book_re_string ='|'.join(b[2] for b in self.books.values()) | ||
| self.book_re = re.compile(self.book_re_string, re.IGNORECASE | re.UNICODE) | ||
| # set instance compiled scripture reference regex | ||
| self.scripture_re = re.compile( | ||
| r'\b(?P<BookTitle>%s)\s*' \ | ||
| '(?P<ChapterNumber>\d{1,3})' \ | ||
| '(?:\s*:\s*(?P<VerseNumber>\d{1,3}))?' \ | ||
| '(?:\s*[-\u2013\u2014]\s*' \ | ||
| '(?P<EndChapterNumber>\d{1,3}(?=\s*:\s*))?' \ | ||
| '(?:\s*:\s*)?' \ | ||
| '(?P<EndVerseNumber>\d{1,3})?' \ | ||
| ')?' % (self.book_re_string,), re.IGNORECASE | re.UNICODE) | ||
| else: | ||
| raise Exception('Text has no "books"') | ||
| def get_book(self, name): | ||
| """ | ||
| Get a book from its name or None if not found | ||
| """ | ||
| for book in self.books.values(): | ||
| if re.match('^%s$' % book[2], name, re.IGNORECASE): | ||
| return book | ||
| return None | ||
| def extract(self, text): | ||
| """ | ||
| Extract a list of tupled scripture references from a block of text | ||
| """ | ||
| references = [] | ||
| for r in re.finditer(self.scripture_re, text): | ||
| try: | ||
| references.append(self.normalize_reference(*r.groups())) | ||
| except InvalidReferenceException: | ||
| pass | ||
| return references | ||
| def is_valid_reference(self, bookname, chapter, verse=None, | ||
| end_chapter=None, end_verse=None): | ||
| """ | ||
| Check to see if a scripture reference is valid | ||
| """ | ||
| try: | ||
| return self.normalize_reference(bookname, chapter, verse, | ||
| end_chapter, end_verse) is not None | ||
| except InvalidReferenceException: | ||
| return False | ||
| def reference_to_string(self, bookname, chapter, verse=None, | ||
| end_chapter=None, end_verse=None): | ||
| """ | ||
| Get a display friendly string from a scripture reference | ||
| """ | ||
| book=None | ||
| bn, c, v, ec, ev = self.normalize_reference(bookname, chapter, verse, | ||
| end_chapter, end_verse) | ||
| book = self.get_book(bn) | ||
| if c == ec and len(book[3]) == 1: # single chapter book | ||
| if v == ev: # single verse | ||
| return '{0} {1}'.format(bn, v) | ||
| else: # multiple verses | ||
| return '{0} {1}-{2}'.format(bn, v, ev) | ||
| else: # multichapter book | ||
| if c == ec: # same start and end chapters | ||
| if v == 1 and ev == book[3][c-1]: # full chapter | ||
| return '{0} {1}'.format(bn, c) | ||
| elif v == ev: # single verse | ||
| return '{0} {1}:{2}'.format(bn, c, v) | ||
| else: # multiple verses | ||
| return '{0} {1}:{2}-{3}'.format( | ||
| bn, c, v, ev) | ||
| else: # multiple chapters | ||
| if v == 1 and ev == book[3][ec-1]: # multichapter ref | ||
| return '{0} {1}-{2}'.format(bn, c, ec) | ||
| else: # multi-chapter, multi-verse ref | ||
| return '{0} {1}:{2}-{3}:{4}'.format(bn, c, v, ec, ev) | ||
| def normalize_reference(self, bookname, chapter, verse=None, | ||
| end_chapter=None, end_verse=None): | ||
| """ | ||
| Get a complete five value tuple scripture reference with full book name | ||
| from partial data | ||
| """ | ||
| book = self.get_book(bookname) | ||
| # SPECIAL CASES FOR: BOOKS WITH ONE CHAPTER AND MULTI-CHAPTER REFERENCES | ||
| # If the ref is in format: (Book, #, None, None, ?) | ||
| # This is a special case and indicates a reference in the format: Book 2-3 | ||
| if chapter is not None and verse is None and end_chapter is None: | ||
| # If there is only one chapter in this book, set the chapter to one and | ||
| # treat the incoming chapter argument as though it were the verse. | ||
| # This normalizes references such as: | ||
| # Jude 2 and Jude 2-4 | ||
| if len(book[3]) == 1: | ||
| verse=chapter | ||
| chapter=1 | ||
| # If the ref is in format: (Book, ?, None, None, #) | ||
| # This normalizes references such as: Revelation 2-3 | ||
| elif end_verse: | ||
| verse=1 | ||
| end_chapter=end_verse | ||
| end_verse=None | ||
| # If the ref is in the format (Book, #, None, #, #) | ||
| # this is a special case that indicates a reference in the format Book 3-4:5 | ||
| elif chapter is not None and verse is None and end_chapter is not None: | ||
| # The solution is to set the verse to one, which is what is | ||
| # most likely intended | ||
| verse = 1 | ||
| # Convert to integers or leave as None | ||
| chapter = int(chapter) if chapter else None | ||
| verse = int(verse) if verse else None | ||
| end_chapter = int(end_chapter) if end_chapter else chapter | ||
| end_verse = int(end_verse) if end_verse else None | ||
| if not book \ | ||
| or (chapter is None or chapter < 1 or chapter > len(book[3])) \ | ||
| or (verse is not None and (verse < 1 or verse > book[3][chapter-1])) \ | ||
| or (end_chapter is not None and ( | ||
| end_chapter < 1 | ||
| or end_chapter < chapter | ||
| or end_chapter > len(book[3]))) \ | ||
| or (end_verse is not None and( | ||
| end_verse < 1 | ||
| or (end_chapter and end_verse > book[3][end_chapter-1]) | ||
| or (chapter == end_chapter and end_verse < verse))): | ||
| raise InvalidReferenceException() | ||
| if not verse: | ||
| return (book[0], chapter, 1, chapter, book[3][chapter-1]) | ||
| if not end_verse: | ||
| if end_chapter and end_chapter != chapter: | ||
| end_verse = book[3][end_chapter-1] | ||
| else: | ||
| end_verse = verse | ||
| if not end_chapter: | ||
| end_chapter = chapter | ||
| return (book[0], chapter, verse, end_chapter, end_verse) | ||
| from __future__ import unicode_literals | ||
| from .base import Text | ||
| class Deuterocanon(Text): | ||
| """ | ||
| Deuterocanonical Books | ||
| """ | ||
| books = { | ||
| 'tob': ('Tobit', 'Tob', 'Tob(?:it)?', | ||
| [22, 14, 17, 21, 22, 17, 18, 21, 6, 12, 19, 22, 18, 15]), | ||
| 'jdt': ('Judith', 'Jdt', 'Jud(?:ith)?', | ||
| [ | ||
| 16, 28, 10, 15, 24, 21, 32, 35, 14, | ||
| 23, 23, 20, 20, 19, 13, 25 | ||
| ]), | ||
| 'addesth': ('Additions to Esther', 'AddEsth', | ||
| '(?:AddEsth|(?:Additions to|Rest of) Esther|Esther \\(Greek\\))', | ||
| [ | ||
| 39, 23, 22, 47, 28, 14, 10, 41, 32, 13 | ||
| ]), | ||
| 'wis': ('The Wisdom of Solomon', 'Wis', | ||
| '(?:The )?Wis(?:dom(?: of Solomon)?)?', | ||
| [ | ||
| 16, 24, 19, 20, 23, 25, 30, 20, 18, | ||
| 21, 26, 27, 19, 31, 19, 29, 21, | ||
| 25, 22 | ||
| ]), | ||
| 'sir': ('Sirach', 'Sir', | ||
| 'Sir(?:ach)?|Ecclesiasticus', | ||
| [ | ||
| 30, 18, 31, 31, 15, 37, 36, 19, 18, | ||
| 31, 34, 18, 26, 27, 20, 30, 32, 33, | ||
| 30, 31, 28, 27, 34, 26, 29, 30, | ||
| 26, 28, 25, 31, 24, 31, 26, 20, | ||
| 26, 31, 34, 35, 30, 23, 25, 33, | ||
| 23, 26, 20, 25, 25, 16, 29, 30 | ||
| ]), | ||
| 'bar': ('Baruch', 'Bar', 'Bar(?:uch)?', | ||
| [ | ||
| 21, 35, 37, 37, 9 | ||
| ]), | ||
| 'epjer': ('Letter of Jeremiah', 'EpJer', | ||
| 'EpJer|Letter of Jeremiah', | ||
| [73]), | ||
| 'prazar': ('Prayer of Azariah', 'prazar', | ||
| '(?:prayer of |Pr)?Azar(?:iah)?|Song of (?:the )?Three Children', | ||
| [68]), | ||
| 'sus': ('Susanna', 'susanna', | ||
| '(?:Story of )?sus(?:anna)?', | ||
| [64]), | ||
| 'bel': ('Bel and the Dragon', 'bel', | ||
| 'bel(?:(?: and the)? dragon)?', | ||
| [42]), | ||
| '1macc': ('I Maccabees', '1Macc', '(?:1|I) ?Macc(?:abees)?', | ||
| [ | ||
| 64, 70, 60, 61, 68, 63, 50, 32, 73, | ||
| 89, 74, 53, 53, 49, 41, 24 | ||
| ]), | ||
| '2macc': ('II Maccabees', '2Macc', '(?:2|II) ?Macc(?:abees)?', | ||
| [ | ||
| 36, 32, 40, 50, 27, 31, 42, 36, 29, | ||
| 38, 38, 45, 26, 46, 39 | ||
| ]), | ||
| } |
| from __future__ import unicode_literals | ||
| from .base import Text | ||
| from .protestant import ProtestantCanon | ||
| from .deuterocanon import Deuterocanon | ||
| class KingJames1611(Text): | ||
| """ | ||
| KingJames1611 - Contains what is considered the protestant canonical texts, | ||
| plus the Deuteronomical books (in its Apocrypha) | ||
| plus its additional Apocryphal books (I and II Esdras) | ||
| """ | ||
| books = {} | ||
| books.update(ProtestantCanon.books) | ||
| books.update(Deuterocanon.books) | ||
| books.update({ | ||
| '1esd': ('I Esdras', '1Esd', '(?:(?:1|I)(?:\s)?)Esd(?:ras)?', | ||
| [58, 30, 24, 63, 73, 34, 15, 96, 55]), | ||
| '2esd': ('II Esdras', '2Esd', '(?:(?:2|II)(?:\s)?)Esd(?:ras)?', | ||
| [40, 48, 36, 52, 56, 59, 70, 63, | ||
| 47, 59, 46, 51, 58, 48, 63, 78]), | ||
| 'prman': ('Prayer of Manasseh', 'prman', | ||
| 'prman|(?:prayer of )?manasseh', | ||
| [15]), | ||
| }) | ||
| from __future__ import unicode_literals | ||
| from .base import Text | ||
| class ProtestantCanon(Text): | ||
| """ | ||
| Protestant Canonical Bible with Old and New Testaments | ||
| """ | ||
| books = { | ||
| 'gen': ('Genesis', 'Gen', 'Gen(?:esis)?', [31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38, 18, 34, 24, 20, 67, 34, 35, 46, 22, 35, 43, 55, 32, 20, 31, 29, 43, 36, 30, 23, 23, 57, 38, 34, 34, 28, 34, 31, 22, 33, 26]), | ||
| 'exod': ('Exodus', 'Exod', 'Exod(?:us)?', [22, 25, 22, 31, 23, 30, 25, 32, 35, 29, 10, 51, 22, 31, 27, 36, 16, 27, 25, 26, 36, 31, 33, 18, 40, 37, 21, 43, 46, 38, 18, 35, 23, 35, 35, 38, 29, 31, 43, 38]), | ||
| 'lev': ('Leviticus', 'Lev', 'Lev(?:iticus)?', [17, 16, 17, 35, 19, 30, 38, 36, 24, 20, 47, 8, 59, 57, 33, 34, 16, 30, 37, 27, 24, 33, 44, 23, 55, 46, 34]), | ||
| 'num': ('Numbers', 'Num', 'Num(?:bers)?', [54, 34, 51, 49, 31, 27, 89, 26, 23, 36, 35, 16, 33, 45, 41, 50, 13, 32, 22, 29, 35, 41, 30, 25, 18, 65, 23, 31, 40, 16, 54, 42, 56, 29, 34, 13]), | ||
| 'deut': ('Deuteronomy', 'Deut', 'Deut(?:eronomy)?', [46, 37, 29, 49, 33, 25, 26, 20, 29, 22, 32, 32, 18, 29, 23, 22, 20, 22, 21, 20, 23, 30, 25, 22, 19, 19, 26, 68, 29, 20, 30, 52, 29, 12]), | ||
| 'josh': ('Joshua', 'Josh', 'Josh(?:ua)?', [18, 24, 17, 24, 15, 27, 26, 35, 27, 43, 23, 24, 33, 15, 63, 10, 18, 28, 51, 9, 45, 34, 16, 33]), | ||
| 'judg': ('Judges', 'Judg', 'Judg(?:es)?', [36, 23, 31, 24, 31, 40, 25, 35, 57, 18, 40, 15, 25, 20, 20, 31, 13, 31, 30, 48, 25]), | ||
| 'ruth': ('Ruth', 'Ruth', 'Ruth', [22, 23, 18, 22]), | ||
| '1sam': ('I Samuel', '1Sam', '(?:1|I)(?:\s)?Sam(?:uel)?', [28, 36, 21, 22, 12, 21, 17, 22, 27, 27, 15, 25, 23, 52, 35, 23, 58, 30, 24, 42, 15, 23, 29, 22, 44, 25, 12, 25, 11, 31, 13]), | ||
| '2sam': ('II Samuel', '2Sam', '(?:2|II)(?:\s)?Sam(?:uel)?', [27, 32, 39, 12, 25, 23, 29, 18, 13, 19, 27, 31, 39, 33, 37, 23, 29, 33, 43, 26, 22, 51, 39, 25]), | ||
| '1kgs': ('I Kings', '1Kgs', '(?:1|I)(?:\s)?K(?:in)?gs', [53, 46, 28, 34, 18, 38, 51, 66, 28, 29, 43, 33, 34, 31, 34, 34, 24, 46, 21, 43, 29, 53]), | ||
| '2kgs': ('II Kings', '2Kgs', '(?:2|II)(?:\s)?K(?:in)?gs', [18, 25, 27, 44, 27, 33, 20, 29, 37, 36, 21, 21, 25, 29, 38, 20, 41, 37, 37, 21, 26, 20, 37, 20, 30]), | ||
| '1chr': ('I Chronicles', '1Chr', '(?:1|I)(?:\s)?Chr(?:o(?:n(?:icles)?)?)?', [54, 55, 24, 43, 26, 81, 40, 40, 44, 14, 47, 40, 14, 17, 29, 43, 27, 17, 19, 8, 30, 19, 32, 31, 31, 32, 34, 21, 30]), | ||
| '2chr': ('II Chronicles', '2Chr', '(?:2|II)(?:\s)?Chr(?:o(?:n(?:icles)?)?)?', [17, 18, 17, 22, 14, 42, 22, 18, 31, 19, 23, 16, 22, 15, 19, 14, 19, 34, 11, 37, 20, 12, 21, 27, 28, 23, 9, 27, 36, 27, 21, 33, 25, 33, 27, 23]), | ||
| 'ezra': ('Ezra', 'Ezra', 'Ezra', [11, 70, 13, 24, 17, 22, 28, 36, 15, 44]), | ||
| 'neh': ('Nehemiah', 'Neh', 'Neh(?:emiah)?', [11, 20, 32, 23, 19, 19, 73, 18, 38, 39, 36, 47, 31]), | ||
| 'esth': ('Esther', 'Esth', 'Esth(?:er)?', [22, 23, 15, 17, 14, 14, 10, 17, 32, 3]), | ||
| 'job': ('Job', 'Job', 'Job', [22, 13, 26, 21, 27, 30, 21, 22, 35, 22, 20, 25, 28, 22, 35, 22, 16, 21, 29, 29, 34, 30, 17, 25, 6, 14, 23, 28, 25, 31, 40, 22, 33, 37, 16, 33, 24, 41, 30, 24, 34, 17]), | ||
| 'ps': ('Psalms', 'Ps', 'Ps(?:a)?(?:lm(?:s)?)?', [6, 12, 8, 8, 12, 10, 17, 9, 20, 18, 7, 8, 6, 7, 5, 11, 15, 50, 14, 9, 13, 31, 6, 10, 22, 12, 14, 9, 11, 12, 24, 11, 22, 22, 28, 12, 40, 22, 13, 17, 13, 11, 5, 26, 17, 11, 9, 14, 20, 23, 19, 9, 6, 7, 23, 13, 11, 11, 17, 12, 8, 12, 11, 10, 13, 20, 7, 35, 36, 5, 24, 20, 28, 23, 10, 12, 20, 72, 13, 19, 16, 8, 18, 12, 13, 17, 7, 18, 52, 17, 16, 15, 5, 23, 11, 13, 12, 9, 9, 5, 8, 28, 22, 35, 45, 48, 43, 13, 31, 7, 10, 10, 9, 8, 18, 19, 2, 29, 176, 7, 8, 9, 4, 8, 5, 6, 5, 6, 8, 8, 3, 18, 3, 3, 21, 26, 9, 8, 24, 13, 10, 7, 12, 15, 21, 10, 20, 14, 9, 6]), | ||
| 'prov': ('Proverbs', 'Prov', 'Prov(?:erbs)?', [33, 22, 35, 27, 23, 35, 27, 36, 18, 32, 31, 28, 25, 35, 33, 33, 28, 24, 29, 30, 31, 29, 35, 34, 28, 28, 27, 28, 27, 33, 31]), | ||
| 'eccl': ('Ecclesiastes', 'Eccl', 'Ecc(?:l(?:es(?:iastes)?)?)?', [18, 26, 22, 16, 20, 12, 29, 17, 18, 20, 10, 14]), | ||
| 'song': ('Song of Solomon', 'Song', 'Song(?: of Sol(?:omon)?)?', [17, 17, 11, 16, 16, 13, 13, 14]), | ||
| 'isa': ('Isaiah', 'Isa', 'Isa(?:iah)?', [31, 22, 26, 6, 30, 13, 25, 22, 21, 34, 16, 6, 22, 32, 9, 14, 14, 7, 25, 6, 17, 25, 18, 23, 12, 21, 13, 29, 24, 33, 9, 20, 24, 17, 10, 22, 38, 22, 8, 31, 29, 25, 28, 28, 25, 13, 15, 22, 26, 11, 23, 15, 12, 17, 13, 12, 21, 14, 21, 22, 11, 12, 19, 12, 25, 24]), | ||
| 'jer': ('Jeremiah', 'Jer', 'Jer(?:emiah)?', [19, 37, 25, 31, 31, 30, 34, 22, 26, 25, 23, 17, 27, 22, 21, 21, 27, 23, 15, 18, 14, 30, 40, 10, 38, 24, 22, 17, 32, 24, 40, 44, 26, 22, 19, 32, 21, 28, 18, 16, 18, 22, 13, 30, 5, 28, 7, 47, 39, 46, 64, 34]), | ||
| 'lam': ('Lamentations', 'Lam', 'Lam(?:entations)?', [22, 22, 66, 22, 22]), | ||
| 'ezek': ('Ezekiel', 'Ezek', 'Ezek(?:iel)?', [28, 10, 27, 17, 17, 14, 27, 18, 11, 22, 25, 28, 23, 23, 8, 63, 24, 32, 14, 49, 32, 31, 49, 27, 17, 21, 36, 26, 21, 26, 18, 32, 33, 31, 15, 38, 28, 23, 29, 49, 26, 20, 27, 31, 25, 24, 23, 35]), | ||
| 'dan': ('Daniel', 'Dan', 'Dan(?:iel)?', [21, 49, 30, 37, 31, 28, 28, 27, 27, 21, 45, 13]), | ||
| 'hos': ('Hosea', 'Hos', 'Hos(?:ea)?', [11, 23, 5, 19, 15, 11, 16, 14, 17, 15, 12, 14, 16, 9]), | ||
| 'joel': ('Joel', 'Joel', 'Joel', [20, 32, 21]), | ||
| 'amos': ('Amos', 'Amos', 'Amos', [15, 16, 15, 13, 27, 14, 17, 14, 15]), | ||
| 'obad': ('Obadiah', 'Obad', 'Obad(?:iah)?', [21]), | ||
| 'jonah': ('Jonah', 'Jonah', 'Jon(?:ah)?', [17, 10, 10, 11]), | ||
| 'mic': ('Micah', 'Mic', 'Mic(?:ah)?', [16, 13, 12, 13, 15, 16, 20]), | ||
| 'nah': ('Nahum', 'Nah', 'Nah(?:um)?', [15, 13, 19]), | ||
| 'hab': ('Habakkuk', 'Hab', 'Hab(?:akkuk)?', [17, 20, 19]), | ||
| 'zeph': ('Zephaniah', 'Zeph', 'Zeph(?:aniah)?', [18, 15, 20]), | ||
| 'hag': ('Haggai', 'Hag', 'Hag(?:gai)?', [15, 23]), | ||
| 'zech': ('Zechariah', 'Zech', 'Zech(?:ariah)?', [21, 13, 10, 14, 11, 15, 14, 23, 17, 12, 17, 14, 9, 21]), | ||
| 'mal': ('Malachi', 'Mal', 'Mal(?:achi)?', [14, 17, 18, 6]), | ||
| 'matt': ('Matthew', 'Matt', 'Matt(?:hew)?', [25, 23, 17, 25, 48, 34, 29, 34, 38, 42, 30, 50, 58, 36, 39, 28, 27, 35, 30, 34, 46, 46, 39, 51, 46, 75, 66, 20]), | ||
| 'mark': ('Mark', 'Mark', 'Mark', [45, 28, 35, 41, 43, 56, 37, 38, 50, 52, 33, 44, 37, 72, 47, 20]), | ||
| 'luke': ('Luke', 'Luke', 'Luke', [80, 52, 38, 44, 39, 49, 50, 56, 62, 42, 54, 59, 35, 35, 32, 31, 37, 43, 48, 47, 38, 71, 56, 53]), | ||
| 'john': ('John', 'John', '(?<!(?:1|2|3|I)\s)(?<!(?:1|2|3|I))John', [51, 25, 36, 54, 47, 71, 53, 59, 41, 42, 57, 50, 38, 31, 27, 33, 26, 40, 42, 31, 25]), | ||
| 'acts': ('Acts', 'Acts', 'Acts', [26, 47, 26, 37, 42, 15, 60, 40, 43, 48, 30, 25, 52, 28, 41, 40, 34, 28, 41, 38, 40, 30, 35, 27, 27, 32, 44, 31]), | ||
| 'rom': ('Romans', 'Rom', 'Rom(?:ans)?', [32, 29, 31, 25, 21, 23, 25, 39, 33, 21, 36, 21, 14, 23, 33, 27]), | ||
| '1cor': ('I Corinthians', '1Cor', '(?:1|I)(?:\s)?Cor(?:inthians)?', [31, 16, 23, 21, 13, 20, 40, 13, 27, 33, 34, 31, 13, 40, 58, 24]), | ||
| '2cor': ('II Corinthians', '2Cor', '(?:2|II)(?:\s)?Cor(?:inthians)?', [24, 17, 18, 18, 21, 18, 16, 24, 15, 18, 33, 21, 14]), | ||
| 'gal': ('Galatians', 'Gal', 'Gal(?:atians)?', [24, 21, 29, 31, 26, 18]), | ||
| 'eph': ('Ephesians', 'Eph', 'Eph(?:esians)?', [23, 22, 21, 32, 33, 24]), | ||
| 'phil': ('Philippians', 'Phil', 'Phil(?:ippians)?', [30, 30, 21, 23]), | ||
| 'col': ('Colossians', 'Col', 'Col(?:ossians)?', [29, 23, 25, 18]), | ||
| '1thess': ('I Thessalonians', '1Thess', '(?:1|I)(?:\s)?Thess(?:alonians)?', [10, 20, 13, 18, 28]), | ||
| '2thess': ('II Thessalonians', '2Thess', '(?:2|II)(?:\s)?Thess(?:alonians)?', [12, 17, 18]), | ||
| '1tim': ('I Timothy', '1Tim', '(?:1|I)(?:\s)?Tim(?:othy)?', [20, 15, 16, 16, 25, 21]), | ||
| '2tim': ('II Timothy', '2Tim', '(?:2|II)(?:\s)?Tim(?:othy)?', [18, 26, 17, 22]), | ||
| 'titus': ('Titus', 'Titus', 'Tit(?:us)?', [16, 15, 15]), | ||
| 'phlm': ('Philemon', 'Phlm', 'Phlm|Phile(?:m(?:on)?)?', [25]), | ||
| 'heb': ('Hebrews', 'Heb', 'Heb(?:rews)?', [14, 18, 19, 16, 14, 20, 28, 13, 28, 39, 40, 29, 25]), | ||
| 'jas': ('James', 'Jas', 'Ja(?:me)?s', [27, 26, 18, 17, 20]), | ||
| '1pet': ('I Peter', '1Pet', '(?:1|I)(?:\s)?Pet(?:er)?', [25, 25, 22, 19, 14]), | ||
| '2pet': ('II Peter', '2Pet', '(?:2|II)(?:\s)?Pet(?:er)?', [21, 22, 18]), | ||
| '1john': ('I John', '1John', '(?:(?:1|I)(?:\s)?)John', [10, 29, 24, 21, 21]), | ||
| '2john': ('II John', '2John', '(?:(?:2|II)(?:\s)?)John', [13]), | ||
| '3john': ('III John', '3John', '(?:(?:3|III)(?:\s)?)John', [14]), | ||
| 'jude': ('Jude', 'Jude', 'Jude', [25]), | ||
| 'rev': ('Revelation of Jesus Christ', 'Rev', 'Rev(?:elation)?(?:\sof Jesus Christ)?', [20, 29, 22, 11, 14, 17, 17, 13, 21, 11, 19, 17, 18, 20, 8, 21, 18, 24, 21, 15, 27, 21]), | ||
| } | ||
+88
-1
| Metadata-Version: 1.0 | ||
| Name: python-scriptures | ||
| Version: 2.2.1 | ||
| Version: 3.0.0 | ||
| Summary: python-scriptures is a Python package and regular expression library for validating, extracting, and normalizing biblical scripture references from blocks of text. | ||
@@ -239,2 +239,89 @@ Home-page: http://www.davisd.com/projects/python-scriptures/ | ||
| Additional Texts | ||
| ================ | ||
| This library currently provides the following texts: | ||
| * protestant - scriptures.texts.protestant.ProtestantCanon | ||
| * deuterocanon - scriptures.texts.deutercanon.Deuterocanon | ||
| * kjv1611 - scriptures.texts.kjv1611.KingJames1611 | ||
| Usage | ||
| ----- | ||
| To use the additional texts, simply instantiate the text object and use the api | ||
| functions and regular expressions on the new instance. | ||
| Example | ||
| ~~~~~~~ | ||
| >>> from scriptures.texts.kjv1611 import KingJames1611 | ||
| >>> myKJV1611 = KingJames1611() | ||
| >>> myKJV1611.extract('the protestant books are implemented- Matthew 1:1-5') | ||
| [(u'Matthew', 1, 1, 1, 5)] | ||
| >>> myKJV1611.extract('and Deuterocanon (apocrypha)- wisdom of solomon 1:1') | ||
| [(u'The Wisdom of Solomon', 1, 1, 1, 1)] | ||
| >>> myKJV1611.extract('and I Esd 1:1, II Esd 1:1, Prayer of Manasseh 1:1') | ||
| [(u'I Esdras', 1, 1, 1, 1), (u'II Esdras', 1, 1, 1, 1), (u'Prayer of Manasseh', 1, 1, 1, 1)] | ||
| Custom Texts | ||
| ============ | ||
| As of v3.0.0, the library makes makes extending the library through custom texts | ||
| trivial through additional modules. Please consider contributing your text | ||
| modules to this project by creating texts under scriptures/texts/ and submitting | ||
| a pull request. | ||
| Creating a New Text | ||
| ------------------- | ||
| To create a new Text, | ||
| 1) Create a class that inherits from scriptures.base.Text | ||
| 2) Implement the "books" dictionary | ||
| 3) Instantiate your new text and use it | ||
| The four api functions will be available from your instance: | ||
| * extract | ||
| * reference_to_string | ||
| * normalize_reference | ||
| * is_valid_reference | ||
| The two regular expressions are also available: | ||
| * book_re | ||
| * scripture_re | ||
| Example | ||
| ~~~~~~~ | ||
| >>> from scriptures.texts.base import Text | ||
| >>> class MyText(Text): | ||
| >>> books = { | ||
| >>> 'test1': ('Test Book 1', 'TBook1', 'test(?:\s)?1', [5, 4, 3, 4, 5]), | ||
| >>> 'test2': ('Test Book 2', 'TBook2', 'test(?:\s)?2', [5, 4, 3, 4, 5]) | ||
| >>> } | ||
| >>> | ||
| >>> mytext = MyText() | ||
| >>> mytext.extract('Ok, testing- test1 1:3-5 and test2 2:4') | ||
| [('Test Book 1', 1, 3, 1, 5), ('Test Book 2', 2, 4, 2, 4)] | ||
| Creating a New Text Using Another As a Starting Point | ||
| ----------------------------------------------------- | ||
| If you would like to use an existing set of books as a starting point, simply | ||
| update your books dictionary using the books from the Text class (or classes) | ||
| that you'd like to use as a starting point. | ||
| For an example of this, see the "KingJames1611" text class in | ||
| scriptures/text/kjv1611.py | ||
| The KingJames1611 Text class uses the ProtestantCanon and Deuterocanon books as | ||
| a starting point and adds I Esdras, II Esdras, and the Prayer of Manasseh. | ||
| Test Suite | ||
@@ -241,0 +328,0 @@ ========== |
+87
-0
@@ -231,2 +231,89 @@ ================= | ||
| Additional Texts | ||
| ================ | ||
| This library currently provides the following texts: | ||
| * protestant - scriptures.texts.protestant.ProtestantCanon | ||
| * deuterocanon - scriptures.texts.deutercanon.Deuterocanon | ||
| * kjv1611 - scriptures.texts.kjv1611.KingJames1611 | ||
| Usage | ||
| ----- | ||
| To use the additional texts, simply instantiate the text object and use the api | ||
| functions and regular expressions on the new instance. | ||
| Example | ||
| ~~~~~~~ | ||
| >>> from scriptures.texts.kjv1611 import KingJames1611 | ||
| >>> myKJV1611 = KingJames1611() | ||
| >>> myKJV1611.extract('the protestant books are implemented- Matthew 1:1-5') | ||
| [(u'Matthew', 1, 1, 1, 5)] | ||
| >>> myKJV1611.extract('and Deuterocanon (apocrypha)- wisdom of solomon 1:1') | ||
| [(u'The Wisdom of Solomon', 1, 1, 1, 1)] | ||
| >>> myKJV1611.extract('and I Esd 1:1, II Esd 1:1, Prayer of Manasseh 1:1') | ||
| [(u'I Esdras', 1, 1, 1, 1), (u'II Esdras', 1, 1, 1, 1), (u'Prayer of Manasseh', 1, 1, 1, 1)] | ||
| Custom Texts | ||
| ============ | ||
| As of v3.0.0, the library makes makes extending the library through custom texts | ||
| trivial through additional modules. Please consider contributing your text | ||
| modules to this project by creating texts under scriptures/texts/ and submitting | ||
| a pull request. | ||
| Creating a New Text | ||
| ------------------- | ||
| To create a new Text, | ||
| 1) Create a class that inherits from scriptures.base.Text | ||
| 2) Implement the "books" dictionary | ||
| 3) Instantiate your new text and use it | ||
| The four api functions will be available from your instance: | ||
| * extract | ||
| * reference_to_string | ||
| * normalize_reference | ||
| * is_valid_reference | ||
| The two regular expressions are also available: | ||
| * book_re | ||
| * scripture_re | ||
| Example | ||
| ~~~~~~~ | ||
| >>> from scriptures.texts.base import Text | ||
| >>> class MyText(Text): | ||
| >>> books = { | ||
| >>> 'test1': ('Test Book 1', 'TBook1', 'test(?:\s)?1', [5, 4, 3, 4, 5]), | ||
| >>> 'test2': ('Test Book 2', 'TBook2', 'test(?:\s)?2', [5, 4, 3, 4, 5]) | ||
| >>> } | ||
| >>> | ||
| >>> mytext = MyText() | ||
| >>> mytext.extract('Ok, testing- test1 1:3-5 and test2 2:4') | ||
| [('Test Book 1', 1, 3, 1, 5), ('Test Book 2', 2, 4, 2, 4)] | ||
| Creating a New Text Using Another As a Starting Point | ||
| ----------------------------------------------------- | ||
| If you would like to use an existing set of books as a starting point, simply | ||
| update your books dictionary using the books from the Text class (or classes) | ||
| that you'd like to use as a starting point. | ||
| For an example of this, see the "KingJames1611" text class in | ||
| scriptures/text/kjv1611.py | ||
| The KingJames1611 Text class uses the ProtestantCanon and Deuterocanon books as | ||
| a starting point and adds I Esdras, II Esdras, and the Prayer of Manasseh. | ||
| Test Suite | ||
@@ -233,0 +320,0 @@ ========== |
@@ -1,99 +0,8 @@ | ||
| from __future__ import unicode_literals | ||
| import re | ||
| from .texts.protestant import ProtestantCanon | ||
| # Testaments, Book Name, Osis Abbreviation (Also preferred abbreviation), Regex, | ||
| # Chapters with Verse counts | ||
| testaments = {'ot': ( | ||
| ('Genesis', 'Gen', 'Gen(?:esis)?', [31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38, 18, 34, 24, 20, 67, 34, 35, 46, 22, 35, 43, 55, 32, 20, 31, 29, 43, 36, 30, 23, 23, 57, 38, 34, 34, 28, 34, 31, 22, 33, 26]), | ||
| ('Exodus', 'Exod', 'Exod(?:us)?', [22, 25, 22, 31, 23, 30, 25, 32, 35, 29, 10, 51, 22, 31, 27, 36, 16, 27, 25, 26, 36, 31, 33, 18, 40, 37, 21, 43, 46, 38, 18, 35, 23, 35, 35, 38, 29, 31, 43, 38]), | ||
| ('Leviticus', 'Lev', 'Lev(?:iticus)?', [17, 16, 17, 35, 19, 30, 38, 36, 24, 20, 47, 8, 59, 57, 33, 34, 16, 30, 37, 27, 24, 33, 44, 23, 55, 46, 34]), | ||
| ('Numbers', 'Num', 'Num(?:bers)?', [54, 34, 51, 49, 31, 27, 89, 26, 23, 36, 35, 16, 33, 45, 41, 50, 13, 32, 22, 29, 35, 41, 30, 25, 18, 65, 23, 31, 40, 16, 54, 42, 56, 29, 34, 13]), | ||
| ('Deuteronomy', 'Deut', 'Deut(?:eronomy)?', [46, 37, 29, 49, 33, 25, 26, 20, 29, 22, 32, 32, 18, 29, 23, 22, 20, 22, 21, 20, 23, 30, 25, 22, 19, 19, 26, 68, 29, 20, 30, 52, 29, 12]), | ||
| ('Joshua', 'Josh', 'Josh(?:ua)?', [18, 24, 17, 24, 15, 27, 26, 35, 27, 43, 23, 24, 33, 15, 63, 10, 18, 28, 51, 9, 45, 34, 16, 33]), | ||
| ('Judges', 'Judg', 'Judg(?:es)?', [36, 23, 31, 24, 31, 40, 25, 35, 57, 18, 40, 15, 25, 20, 20, 31, 13, 31, 30, 48, 25]), | ||
| ('Ruth', 'Ruth', 'Ruth', [22, 23, 18, 22]), | ||
| ('I Samuel', '1Sam', '(?:1|I)(?:\s)?Sam(?:uel)?', [28, 36, 21, 22, 12, 21, 17, 22, 27, 27, 15, 25, 23, 52, 35, 23, 58, 30, 24, 42, 15, 23, 29, 22, 44, 25, 12, 25, 11, 31, 13]), | ||
| ('II Samuel', '2Sam', '(?:2|II)(?:\s)?Sam(?:uel)?', [27, 32, 39, 12, 25, 23, 29, 18, 13, 19, 27, 31, 39, 33, 37, 23, 29, 33, 43, 26, 22, 51, 39, 25]), | ||
| ('I Kings', '1Kgs', '(?:1|I)(?:\s)?K(?:in)?gs', [53, 46, 28, 34, 18, 38, 51, 66, 28, 29, 43, 33, 34, 31, 34, 34, 24, 46, 21, 43, 29, 53]), | ||
| ('II Kings', '2Kgs', '(?:2|II)(?:\s)?K(?:in)?gs', [18, 25, 27, 44, 27, 33, 20, 29, 37, 36, 21, 21, 25, 29, 38, 20, 41, 37, 37, 21, 26, 20, 37, 20, 30]), | ||
| ('I Chronicles', '1Chr', '(?:1|I)(?:\s)?Chr(?:o(?:n(?:icles)?)?)?', [54, 55, 24, 43, 26, 81, 40, 40, 44, 14, 47, 40, 14, 17, 29, 43, 27, 17, 19, 8, 30, 19, 32, 31, 31, 32, 34, 21, 30]), | ||
| ('II Chronicles', '2Chr', '(?:2|II)(?:\s)?Chr(?:o(?:n(?:icles)?)?)?', [17, 18, 17, 22, 14, 42, 22, 18, 31, 19, 23, 16, 22, 15, 19, 14, 19, 34, 11, 37, 20, 12, 21, 27, 28, 23, 9, 27, 36, 27, 21, 33, 25, 33, 27, 23]), | ||
| ('Ezra', 'Ezra', 'Ezra', [11, 70, 13, 24, 17, 22, 28, 36, 15, 44]), | ||
| ('Nehemiah', 'Neh', 'Neh(?:emiah)?', [11, 20, 32, 23, 19, 19, 73, 18, 38, 39, 36, 47, 31]), | ||
| ('Esther', 'Esth', 'Esth(?:er)?', [22, 23, 15, 17, 14, 14, 10, 17, 32, 3]), | ||
| ('Job', 'Job', 'Job', [22, 13, 26, 21, 27, 30, 21, 22, 35, 22, 20, 25, 28, 22, 35, 22, 16, 21, 29, 29, 34, 30, 17, 25, 6, 14, 23, 28, 25, 31, 40, 22, 33, 37, 16, 33, 24, 41, 30, 24, 34, 17]), | ||
| ('Psalms', 'Ps', 'Ps(?:a)?(?:lm(?:s)?)?', [6, 12, 8, 8, 12, 10, 17, 9, 20, 18, 7, 8, 6, 7, 5, 11, 15, 50, 14, 9, 13, 31, 6, 10, 22, 12, 14, 9, 11, 12, 24, 11, 22, 22, 28, 12, 40, 22, 13, 17, 13, 11, 5, 26, 17, 11, 9, 14, 20, 23, 19, 9, 6, 7, 23, 13, 11, 11, 17, 12, 8, 12, 11, 10, 13, 20, 7, 35, 36, 5, 24, 20, 28, 23, 10, 12, 20, 72, 13, 19, 16, 8, 18, 12, 13, 17, 7, 18, 52, 17, 16, 15, 5, 23, 11, 13, 12, 9, 9, 5, 8, 28, 22, 35, 45, 48, 43, 13, 31, 7, 10, 10, 9, 8, 18, 19, 2, 29, 176, 7, 8, 9, 4, 8, 5, 6, 5, 6, 8, 8, 3, 18, 3, 3, 21, 26, 9, 8, 24, 13, 10, 7, 12, 15, 21, 10, 20, 14, 9, 6]), | ||
| ('Proverbs', 'Prov', 'Prov(?:erbs)?', [33, 22, 35, 27, 23, 35, 27, 36, 18, 32, 31, 28, 25, 35, 33, 33, 28, 24, 29, 30, 31, 29, 35, 34, 28, 28, 27, 28, 27, 33, 31]), | ||
| ('Ecclesiastes', 'Eccl', 'Ecc(?:l(?:es(?:iastes)?)?)?', [18, 26, 22, 16, 20, 12, 29, 17, 18, 20, 10, 14]), | ||
| ('Song of Solomon', 'Song', 'Song(?: of Sol(?:omon)?)?', [17, 17, 11, 16, 16, 13, 13, 14]), | ||
| ('Isaiah', 'Isa', 'Isa(?:iah)?', [31, 22, 26, 6, 30, 13, 25, 22, 21, 34, 16, 6, 22, 32, 9, 14, 14, 7, 25, 6, 17, 25, 18, 23, 12, 21, 13, 29, 24, 33, 9, 20, 24, 17, 10, 22, 38, 22, 8, 31, 29, 25, 28, 28, 25, 13, 15, 22, 26, 11, 23, 15, 12, 17, 13, 12, 21, 14, 21, 22, 11, 12, 19, 12, 25, 24]), | ||
| ('Jeremiah', 'Jer', 'Jer(?:emiah)?', [19, 37, 25, 31, 31, 30, 34, 22, 26, 25, 23, 17, 27, 22, 21, 21, 27, 23, 15, 18, 14, 30, 40, 10, 38, 24, 22, 17, 32, 24, 40, 44, 26, 22, 19, 32, 21, 28, 18, 16, 18, 22, 13, 30, 5, 28, 7, 47, 39, 46, 64, 34]), | ||
| ('Lamentations', 'Lam', 'Lam(?:entations)?', [22, 22, 66, 22, 22]), | ||
| ('Ezekiel', 'Ezek', 'Ezek(?:iel)?', [28, 10, 27, 17, 17, 14, 27, 18, 11, 22, 25, 28, 23, 23, 8, 63, 24, 32, 14, 49, 32, 31, 49, 27, 17, 21, 36, 26, 21, 26, 18, 32, 33, 31, 15, 38, 28, 23, 29, 49, 26, 20, 27, 31, 25, 24, 23, 35]), | ||
| ('Daniel', 'Dan', 'Dan(?:iel)?', [21, 49, 30, 37, 31, 28, 28, 27, 27, 21, 45, 13]), | ||
| ('Hosea', 'Hos', 'Hos(?:ea)?', [11, 23, 5, 19, 15, 11, 16, 14, 17, 15, 12, 14, 16, 9]), | ||
| ('Joel', 'Joel', 'Joel', [20, 32, 21]), | ||
| ('Amos', 'Amos', 'Amos', [15, 16, 15, 13, 27, 14, 17, 14, 15]), | ||
| ('Obadiah', 'Obad', 'Obad(?:iah)?', [21]), | ||
| ('Jonah', 'Jonah', 'Jon(?:ah)?', [17, 10, 10, 11]), | ||
| ('Micah', 'Mic', 'Mic(?:ah)?', [16, 13, 12, 13, 15, 16, 20]), | ||
| ('Nahum', 'Nah', 'Nah(?:um)?', [15, 13, 19]), | ||
| ('Habakkuk', 'Hab', 'Hab(?:akkuk)?', [17, 20, 19]), | ||
| ('Zephaniah', 'Zeph', 'Zeph(?:aniah)?', [18, 15, 20]), | ||
| ('Haggai', 'Hag', 'Hag(?:gai)?', [15, 23]), | ||
| ('Zechariah', 'Zech', 'Zech(?:ariah)?', [21, 13, 10, 14, 11, 15, 14, 23, 17, 12, 17, 14, 9, 21]), | ||
| ('Malachi', 'Mal', 'Mal(?:achi)?', [14, 17, 18, 6]), | ||
| ), | ||
| 'nt': ( | ||
| ('Matthew', 'Matt', 'Matt(?:hew)?', [25, 23, 17, 25, 48, 34, 29, 34, 38, 42, 30, 50, 58, 36, 39, 28, 27, 35, 30, 34, 46, 46, 39, 51, 46, 75, 66, 20]), | ||
| ('Mark', 'Mark', 'Mark', [45, 28, 35, 41, 43, 56, 37, 38, 50, 52, 33, 44, 37, 72, 47, 20]), | ||
| ('Luke', 'Luke', 'Luke', [80, 52, 38, 44, 39, 49, 50, 56, 62, 42, 54, 59, 35, 35, 32, 31, 37, 43, 48, 47, 38, 71, 56, 53]), | ||
| ('John', 'John', '(?<!(?:1|2|3|I)\s)(?<!(?:1|2|3|I))John', [51, 25, 36, 54, 47, 71, 53, 59, 41, 42, 57, 50, 38, 31, 27, 33, 26, 40, 42, 31, 25]), | ||
| ('Acts', 'Acts', 'Acts', [26, 47, 26, 37, 42, 15, 60, 40, 43, 48, 30, 25, 52, 28, 41, 40, 34, 28, 41, 38, 40, 30, 35, 27, 27, 32, 44, 31]), | ||
| ('Romans', 'Rom', 'Rom(?:ans)?', [32, 29, 31, 25, 21, 23, 25, 39, 33, 21, 36, 21, 14, 23, 33, 27]), | ||
| ('I Corinthians', '1Cor', '(?:1|I)(?:\s)?Cor(?:inthians)?', [31, 16, 23, 21, 13, 20, 40, 13, 27, 33, 34, 31, 13, 40, 58, 24]), | ||
| ('II Corinthians', '2Cor', '(?:2|II)(?:\s)?Cor(?:inthians)?', [24, 17, 18, 18, 21, 18, 16, 24, 15, 18, 33, 21, 14]), | ||
| ('Galatians', 'Gal', 'Gal(?:atians)?', [24, 21, 29, 31, 26, 18]), | ||
| ('Ephesians', 'Eph', 'Eph(?:esians)?', [23, 22, 21, 32, 33, 24]), | ||
| ('Philippians', 'Phil', 'Phil(?:ippians)?', [30, 30, 21, 23]), | ||
| ('Colossians', 'Col', 'Col(?:ossians)?', [29, 23, 25, 18]), | ||
| ('I Thessalonians', '1Thess', '(?:1|I)(?:\s)?Thess(?:alonians)?', [10, 20, 13, 18, 28]), | ||
| ('II Thessalonians', '2Thess', '(?:2|II)(?:\s)?Thess(?:alonians)?', [12, 17, 18]), | ||
| ('I Timothy', '1Tim', '(?:1|I)(?:\s)?Tim(?:othy)?', [20, 15, 16, 16, 25, 21]), | ||
| ('II Timothy', '2Tim', '(?:2|II)(?:\s)?Tim(?:othy)?', [18, 26, 17, 22]), | ||
| ('Titus', 'Titus', 'Tit(?:us)?', [16, 15, 15]), | ||
| ('Philemon', 'Phlm', 'Phlm|Phile(?:m(?:on)?)?', [25]), | ||
| ('Hebrews', 'Heb', 'Heb(?:rews)?', [14, 18, 19, 16, 14, 20, 28, 13, 28, 39, 40, 29, 25]), | ||
| ('James', 'Jas', 'Ja(?:me)?s', [27, 26, 18, 17, 20]), | ||
| ('I Peter', '1Pet', '(?:1|I)(?:\s)?Pet(?:er)?', [25, 25, 22, 19, 14]), | ||
| ('II Peter', '2Pet', '(?:2|II)(?:\s)?Pet(?:er)?', [21, 22, 18]), | ||
| ('I John', '1John', '(?:(?:1|I)(?:\s)?)John', [10, 29, 24, 21, 21]), | ||
| ('II John', '2John', '(?:(?:2|II)(?:\s)?)John', [13]), | ||
| ('III John', '3John', '(?:(?:3|III)(?:\s)?)John', [14]), | ||
| ('Jude', 'Jude', 'Jude', [25]), | ||
| ('Revelation of Jesus Christ', 'Rev', 'Rev(?:elation)?(?:\sof Jesus Christ)?', [20, 29, 22, 11, 14, 17, 17, 13, 21, 11, 19, 17, 18, 20, 8, 21, 18, 24, 21, 15, 27, 21]), | ||
| ),} | ||
| # create an instance of the Protestant Canon to use as the default | ||
| pcanon=ProtestantCanon() | ||
| def get_book_re(): | ||
| """ | ||
| Get a regular expression string that will match any book of the Bible | ||
| """ | ||
| return '|'.join(b[2] for b in testaments['ot'] + testaments['nt']) | ||
| book_re = pcanon.book_re | ||
| scripture_re = pcanon.scripture_re | ||
| # assemble the book regex | ||
| book_re_string=get_book_re() | ||
| # compiled book regular expression | ||
| book_re = re.compile(book_re_string, re.IGNORECASE | re.UNICODE) | ||
| # compiled scripture reference regular expression | ||
| scripture_re = re.compile( | ||
| r'\b(?P<BookTitle>%s)\s*' \ | ||
| '(?P<ChapterNumber>\d{1,3})' \ | ||
| '(?:\s*:\s*(?P<VerseNumber>\d{1,3}))?' \ | ||
| '(?:\s*[-\u2013\u2014]\s*' \ | ||
| '(?P<EndChapterNumber>\d{1,3}(?=\s*:\s*))?' \ | ||
| '(?:\s*:\s*)?' \ | ||
| '(?P<EndVerseNumber>\d{1,3})?' \ | ||
| ')?' % (book_re_string,), re.IGNORECASE | re.UNICODE) | ||
+20
-107
@@ -1,11 +0,15 @@ | ||
| import re | ||
| from .bible_re import pcanon | ||
| from .texts import InvalidReferenceException | ||
| from .bible_re import testaments, book_re, scripture_re | ||
| # The functions below are shortcut-functions to the ProtestantCanon text | ||
| # The same functions could be verbosely accessed with: | ||
| # | ||
| # >>> from scriptures.texts.protestant import ProtestantCanon | ||
| # >>> pc=ProtestantCanon() | ||
| # | ||
| # The instance variable "pc" has the functions: get_book, extract, | ||
| # is_valid_reference, reference_to_string, and normalize_reference | ||
| # | ||
| # For instructions on using a different Text, see the documentation | ||
| class InvalidReferenceException(Exception): | ||
| """ | ||
| Invalid Reference Exception | ||
| """ | ||
| pass | ||
| def get_book(name): | ||
@@ -15,7 +19,3 @@ """ | ||
| """ | ||
| for books in testaments.values(): | ||
| for book in books: | ||
| if re.match('^%s$' % book[2], name, re.IGNORECASE): | ||
| return book | ||
| return None | ||
| return pcanon.get_book(name) | ||
@@ -26,9 +26,3 @@ def extract(text): | ||
| """ | ||
| references = [] | ||
| for r in re.finditer(scripture_re, text): | ||
| try: | ||
| references.append(normalize_reference(*r.groups())) | ||
| except InvalidReferenceException: | ||
| pass | ||
| return references | ||
| return pcanon.extract(text) | ||
@@ -40,7 +34,4 @@ def is_valid_reference(bookname, chapter, verse=None, | ||
| """ | ||
| try: | ||
| return normalize_reference(bookname, chapter, verse, | ||
| end_chapter, end_verse) is not None | ||
| except InvalidReferenceException: | ||
| return False | ||
| return pcanon.is_valid_reference(bookname, chapter, verse, end_chapter, | ||
| end_verse) | ||
@@ -52,29 +43,5 @@ def reference_to_string(bookname, chapter, verse=None, | ||
| """ | ||
| book=None | ||
| return pcanon.reference_to_string(bookname, chapter, verse, | ||
| end_chapter, end_verse) | ||
| bn, c, v, ec, ev = normalize_reference(bookname, chapter, verse, | ||
| end_chapter, end_verse) | ||
| book = get_book(bn) | ||
| if c == ec and len(book[3]) == 1: # single chapter book | ||
| if v == ev: # single verse | ||
| return '{0} {1}'.format(bn, v) | ||
| else: # multiple verses | ||
| return '{0} {1}-{2}'.format(bn, v, ev) | ||
| else: # multichapter book | ||
| if c == ec: # same start and end chapters | ||
| if v == 1 and ev == book[3][c-1]: # full chapter | ||
| return '{0} {1}'.format(bn, c) | ||
| elif v == ev: # single verse | ||
| return '{0} {1}:{2}'.format(bn, c, v) | ||
| else: # multiple verses | ||
| return '{0} {1}:{2}-{3}'.format( | ||
| bn, c, v, ev) | ||
| else: # multiple chapters | ||
| if v == 1 and ev == book[3][ec-1]: # multichapter ref | ||
| return '{0} {1}-{2}'.format(bn, c, ec) | ||
| else: # multi-chapter, multi-verse ref | ||
| return '{0} {1}:{2}-{3}:{4}'.format(bn, c, v, ec, ev) | ||
| def normalize_reference(bookname, chapter, verse=None, | ||
@@ -86,58 +53,4 @@ end_chapter=None, end_verse=None): | ||
| """ | ||
| book = get_book(bookname) | ||
| return pcanon.normalize_reference(bookname, chapter, verse, end_chapter, | ||
| end_verse) | ||
| # SPECIAL CASES FOR: BOOKS WITH ONE CHAPTER AND MULTI-CHAPTER REFERENCES | ||
| # If the ref is in format: (Book, #, None, None, ?) | ||
| # This is a special case and indicates a reference in the format: Book 2-3 | ||
| if chapter is not None and verse is None and end_chapter is None: | ||
| # If there is only one chapter in this book, set the chapter to one and | ||
| # treat the incoming chapter argument as though it were the verse. | ||
| # This normalizes references such as: | ||
| # Jude 2 and Jude 2-4 | ||
| if len(book[3]) == 1: | ||
| verse=chapter | ||
| chapter=1 | ||
| # If the ref is in format: (Book, ?, None, None, #) | ||
| # This normalizes references such as: Revelation 2-3 | ||
| elif end_verse: | ||
| verse=1 | ||
| end_chapter=end_verse | ||
| end_verse=None | ||
| # If the ref is in the format (Book, #, None, #, #) | ||
| # this is a special case that indicates a reference in the format Book 3-4:5 | ||
| elif chapter is not None and verse is None and end_chapter is not None: | ||
| # The solution is to set the verse to one, which is what is | ||
| # most likely intended | ||
| verse = 1 | ||
| # Convert to integers or leave as None | ||
| chapter = int(chapter) if chapter else None | ||
| verse = int(verse) if verse else None | ||
| end_chapter = int(end_chapter) if end_chapter else chapter | ||
| end_verse = int(end_verse) if end_verse else None | ||
| if not book \ | ||
| or (chapter is None or chapter < 1 or chapter > len(book[3])) \ | ||
| or (verse is not None and (verse < 1 or verse > book[3][chapter-1])) \ | ||
| or (end_chapter is not None and ( | ||
| end_chapter < 1 | ||
| or end_chapter < chapter | ||
| or end_chapter > len(book[3]))) \ | ||
| or (end_verse is not None and( | ||
| end_verse < 1 | ||
| or (end_chapter and end_verse > book[3][end_chapter-1]) | ||
| or (chapter == end_chapter and end_verse < verse))): | ||
| raise InvalidReferenceException() | ||
| if not verse: | ||
| return (book[0], chapter, 1, chapter, book[3][chapter-1]) | ||
| if not end_verse: | ||
| if end_chapter and end_chapter != chapter: | ||
| end_verse = book[3][end_chapter-1] | ||
| else: | ||
| end_verse = verse | ||
| if not end_chapter: | ||
| end_chapter = chapter | ||
| return (book[0], chapter, verse, end_chapter, end_verse) | ||
+2
-2
@@ -5,6 +5,6 @@ from distutils.core import setup | ||
| name='python-scriptures', | ||
| version='2.2.1', | ||
| version='3.0.0', | ||
| author='David Davis', | ||
| author_email='davisd@davisd.com', | ||
| packages=['scriptures',], | ||
| packages=['scriptures', 'scriptures/texts'], | ||
| url='http://www.davisd.com/projects/python-scriptures/', | ||
@@ -11,0 +11,0 @@ data_files=[('.',['LICENSE'])], |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
42385
45.76%12
71.43%372
58.97%