bible-ref-py is a python library built on top of python-scriptures library, implemented by David Davis <davisd@davisd.com> (Copyright (c) 2010-2015). It is a Python package and regular expression library for validating, extracting, and normalizing biblical references from text.
Project description
bible-ref-py
bible-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 by Beatitud developers, on top of python-scriptures library, initially implemented by David Davis (Copyright (c) 2010-2015).
Typical usage is as follows:
from scriptures.text import Text
string = "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.
from scriptures.reference import Reference
Reference(book='Rom', chapter=2, verse=30).is_valid()
# False
Reference(book='Rom', chapter=3, verse=23).is_valid()
# True
Single 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 reference
- Else, 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 reference
- Else, if there is a complete reference in the text, in the previous paragraphs, we suppose the single verse refers to those books and chapters
from scriptures.text import Text
string = "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)>]
Installation
To install, simply run the script with the install command:
$ pip install beatitud-scriptures
Or just put the scriptures package somewhere on the Python path.
API
Return Values
When a "scripture reference" is returned, it is always an object with five attributes consisting of:
- book
- chapter
- verse
- end_chapter
- end_verse
from scriptures.reference import Reference
ref = Reference(book='Rom', chapter=2, verse=30)
print(ref.book)
# Romans
print(ref.chapter)
# 2
Regular Expressions
There are two compiled regular expression patterns exposed by this package.
book_re
Match a valid abbreviation or book name.
Examples:
from scriptures.canons import get_canon
import re
canon = get_canon(name="catholic")
re.findall(canon.book_re, 'Matt test Ecclesiastes and 2 peter')
# ['Matt', 'Ecclesiastes', '2 peter']
scripture_re
Match a scripture reference pattern from a valid abbreviation or book name.
Examples:
from scriptures.text import Text
import re
txt = 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')]
Canons
This library currently provides the following canons:
- catholic - scriptures.canons.catholic.Canon
- protestant - scriptures.canons.protestant.Canon
- deuterocanon - scriptures.canons.deutercanon.Canon
- kjv1611 - scriptures.canons.kjv1611.Canon
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.canons.catholic import Canon
cc = 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 Canons
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 canons under scriptures/canons/ and submitting a pull request.
Creating a New Canon
To create a new Canon,
- Create a class that inherits from scriptures.base.CanonBase
- Implement the "books" dictionary
- Instantiate your new canon and use it
Test Suite
Unit 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file beatitud_scriptures-4.0.0-py3-none-any.whl
.
File metadata
- Download URL: beatitud_scriptures-4.0.0-py3-none-any.whl
- Upload date:
- Size: 39.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f37391bb4e9448f0dd0874466c7648bcb1574b4eb3299d6744d64a6eb38776b7 |
|
MD5 | c5a11bd62f34bdf6a07d1f725372b7c4 |
|
BLAKE2b-256 | 2f1fea1114fdeeecc63a0a2b9281911402c70e06a6ae99e2dff3a1a6aa2def97 |
File details
Details for the file beatitud_scriptures-4.0.0-py2-none-any.whl
.
File metadata
- Download URL: beatitud_scriptures-4.0.0-py2-none-any.whl
- Upload date:
- Size: 39.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c6a7d4962e5586af916814b02111a4221f98dcb5de617638b52279d5f89f3a |
|
MD5 | f102bc4f2e3399808c8d78e387653429 |
|
BLAKE2b-256 | aefdcc9784cf530b7de893911750bdcd122b3809e238bb2093dfff1dba088263 |