Package: beatitud-scriptures
bible-ref-pybible-ref-py is a Python 2 and Python 3 compatible package and regular
expression library for validating, extracting and normalizing biblical
references from texts.bible-ref-py is built byBeatitud developers, on top of python-scriptures library, initially implemented byDavid Davis(Copyright (c) 2010-2015).Typical usage is as follows:fromscriptures.textimportTextstring="Le service est le billet à présenter à l’entrée des noces éternelles. Ce qui reste de la vie au seuil de l’éternité, ce n’est pas ce que nous avons gagné, mais ce que nous avons donné (cf. Mt 6, 19-21 ; 1Co 13, 8)"text=Text(string,language='fr',canon='catholic')text.extract_refs(guess=True)# [<Ref(Matthieu 6:19-21)>, <Ref(I Corinthiens 13:8)>]Range validation is performed automatically and invalid references are not
extracted.fromscriptures.referenceimportReferenceReference(book='Rom',chapter=2,verse=30).is_valid()# FalseReference(book='Rom',chapter=3,verse=23).is_valid()# TrueSingle verse number references can be guessed, according to three rules:If there is a complete reference in the same sentence, before, we suppose the single verse refers to the same books and chapters than this complete referenceElse, if there is a complete reference in the same paragraph, before, we suppose the single verse refers to the same books and chapters than this complete referenceElse, if there is a complete reference in the text, in the previous paragraphs, we suppose the single verse refers to those books and chaptersfromscriptures.textimportTextstring="Les disciples « sortirent à la rencontre de l’époux » (Mt 25, 1). Puis : « Voici l’époux, sortez à sa rencontre ! » (v. 6)."text=Text(string,language='fr',canon='catholic')text.extract_refs(guess=True)# [<Ref(Matthieu 25:1)>, <Ref(Matthieu 25:6)>]InstallationTo install, simply run the script with the install command:$pipinstallbeatitud-scripturesOr just put the scriptures package somewhere on the Python path.APIReturn ValuesWhen a "scripture reference" is returned, it is always an object with five attributes
consisting of:bookchapterverseend_chapterend_versefromscriptures.referenceimportReferenceref=Reference(book='Rom',chapter=2,verse=30)print(ref.book)# Romansprint(ref.chapter)# 2Regular ExpressionsThere are two compiled regular expression patterns exposed by this package.book_reMatch a valid abbreviation or book name.Examples:fromscriptures.canonsimportget_canonimportrecanon=get_canon(name="catholic")re.findall(canon.book_re,'Matt test Ecclesiastes and 2 peter')# ['Matt', 'Ecclesiastes', '2 peter']scripture_reMatch a scripture reference pattern from a valid abbreviation or book name.Examples:fromscriptures.textimportTextimportretxt=Text("",language="en",canon="catholic")re.findall(txt.scripture_re,'Matt 3 & Acts 1:2-3 Rev 2:1-3:2')# [('Matt', '3', '', '', ''), ('Acts', '1', '2', '', '3'),# ('Rev', '2', '1', '3', '2')]CanonsThis library currently provides the following canons:catholic - scriptures.canons.catholic.Canonprotestant - scriptures.canons.protestant.Canondeuterocanon - scriptures.canons.deutercanon.Canonkjv1611 - scriptures.canons.kjv1611.CanonUsageTo use the additional texts, simply instantiate the text object and use the api
functions and regular expressions on the new instance.Examplefromscriptures.canons.catholicimportCanoncc=Canon(language='en')print(cc.books)# {'gn': {#                'en': ('Genesis', 'Gen', 'Gen(?:esis)?'),#                'fr': ('Genèse', 'Gn', 'Gen(?:èse)?'),#                'chapters':#                    [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]#  },#  ...}Custom CanonsThe library makes makes extending the library through custom texts
trivial through additional modules.  Please consider contributing your text
modules to this project by creating canons under scriptures/canons/ and submitting
a pull request.Creating a New CanonTo create a new Canon,Create a class that inherits from scriptures.base.CanonBaseImplement the "books" dictionaryInstantiate your new canon and use itTest SuiteUnit tests are provided to verify chapter and verse style normalization, output
formatting, and book names and abbreviations.To run the test suite, cwd to just outside of the scriptures package and:$ python -m unittest discover