Skip to main content

PARSE and PROCESS BIBLE SCRIPTURE REFERENCES: extract, tag, link, rewrite, translate, BCV-encode and decode

Project description

Static Badge Static Badge Static Badge

Purpose

This module contains functions to parse and process Bible scripture references.

The parser can work in Cebuano, Chinese, Danish, Dutch, English, Ewe, French, German, Greek, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Russian, Spanish, Swedish, Tagalog and Ukrainian. It will recognize such references and validate them to ensure the chapter(s) and/or verse(s) are within range.

It does not work with whole books (like "James") unless they are preceded by a number (like "1 John"); otherwise it would have to look up ever single word. Also, it will not find the multi-word book name "Song of Solomon" (and its variations), though this (and any other scripture) can be force-detected by tagging the desired reference "manually" within the source text (eg., "{{Song of Solomon 1:1}}") - one book per brace pair. These two limitations aside, it works with most book name variants in all the available languages (including common abbreviations): "2 Sam.", "2nd Samuel", "II Samuel", "2Sa", etc. Any special/unusual variants can be added to the res/custom.json list.

These found references can be extracted as a list of references, or a list of BCV-encoded ranges in the format bbcccvvv (where b is book, c is chapter, and v is verse). Or, they can be tagged (with '{{ }}') within the text, or replaced with HTML <a> links (with custom prefix and suffix). All of these functions can also include a rewrite of the reference with either a full book name, or one of two abbreviation formats, along with translation into one of the available languages.

The parser tries to deal "intelligently" with different notations, but there are simply too many "edge-cases". If something isn't being parsed properly, try to rewrite the original reference(s) in a standard way or use {{ }} to force the detection.

A couple of auxiliary functions provide a verse number lookup (either by BCV reference or integer). These can be useful to calculate the number of verses between two references, etc.


Installation

python3 -m pip install linkture


Command-line usage

> python3 -m linkture -h
usage: linkture.py [-h] [-v] [-q] [-f in-file | -r reference] [-o out-file]
                   [--language {Cebuano,Chinese,Danish,Dutch,English,Ewe,French,German,Greek,Hungarian,Italian,Japanese,Korean,Norwegian,Polish,Portuguese,Russian,Spanish,Tagalog,Ukrainian}]
                   [--translate {Cebuano,Chinese,Danish,Dutch,English,Ewe,French,German,Greek,Hungarian,Italian,Japanese,Korean,Norwegian,Polish,Portuguese,Russian,Spanish,Tagalog,Ukrainian}]
                   [-s separator] [-u] [--full | --official | --standard]
                   [-c | -d | -l [prefix [suffix ...]] | -t | -x]
                   [-sc BCV | -sv BCV | -cc chapter | -cv verse]

PARSE and PROCESS BIBLE SCRIPTURE REFERENCES: extract, tag, link, rewrite, translate, BCV-encode and decode.
See README for more information

options:
  -h, --help            show this help message and exit
  -v                    show version and exit
  -q                    don't show errors
  -o out-file           output file (terminal output if not provided)
  --language {Cebuano,Chinese,Danish,Dutch,English,Ewe,French,German,Greek,Hungarian,Italian,Japanese,Korean,Norwegian,Polish,Portuguese,Russian,Spanish,Tagalog,Ukrainian}
                        indicate source language for book names (English if unspecified)
  --translate {Cebuano,Chinese,Danish,Dutch,English,Ewe,French,German,Greek,Hungarian,Italian,Japanese,Korean,Norwegian,Polish,Portuguese,Russian,Spanish,Tagalog,Ukrainian}
                        indicate output language for book names (same as source if unspecified)
  -s separator          segment separator (space by default)
  -u                    capitalize (upper-case) book names

data source (one required - except for auxiliary functions, which only take command-line arguments):
  choose between terminal or file input:

  -f in-file            get input from file (UTF-8)
  -r reference          process "reference; reference; etc."

output format (optional):
  if provided, book names will be rewritten accordingly:

  --full                output as full name - default (eg., "Genesis")
  --official            output as official abbreviation (eg., "Ge")
  --standard            output as standard abbreviation (eg., "Gen.")

type of conversion:
  if not specified, references are simply rewritten according to chosen (or default) output format:

  -c                    encode as BCV-notation ranges
  -d                    decode list of BCV-notation ranges
  -l [prefix [suffix ...]]
                        create <a></a> links; provide a "prefix" and a "suffix" (or neither for testing)
  -t                    tag scriptures with {{ }}
  -x                    extract list of scripture references

auxiliary functions:
  -sc BCV               return the serial number (1-1189) of the chapter with code "BCV" ("bbcccvvv")
  -sv BCV               return the serial number (1-31091) of the verse with code "BCV" ("bbcccvvv")
  -cc chapter           return the BCV range for serial chapter number "chapter" (integer value)
  -cv verse             return the BCV code for serial verse number "verse" (integer value)

Some examples:

$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" --full -u
JOHN 17:17; 2 TIMOTHY 3:16, 17

$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" --standard
John 17:17; 2 Tim. 3:16, 17

$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" --official
Joh 17:17; 2Ti 3:16, 17


$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" -c
[('43017017', '43017017'), ('55003016', '55003017')]

$ python3 -m linkture -r "[('43017017', '43017017'), ('55003016', '55003017')]" -d --translate German
['Johannes 17:17', '2. Timotheus 3:16, 17']


$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" -l '<a href="https://my.website.com/' '/index.html" class="test">'
<a href="https://my.website.com/43:17:17/index.html" class="test">John 17:17</a>; <a href="https://my.website.com/55:3:16-55:3:17/index.html" class="test">2 Timothy 3:16, 17</a>


$ python3 -m linkture -r "Joh 17:17; 2Ti 3:16, 17" --translate Chinese
约翰福音 17:17; 提摩太后书 3:16, 17

$ python3 -m linkture -r "约翰福音 17:17; 提摩太后书 3:16, 17" --language Chinese --translate Dutch
Johannes 17:17; 2 Timotheüs 3:16, 17

$ python3 -m linkture -r "{{Jean 17:17}}; 2 Timothée 3:16, 17" --language French --translate Spanish --standard
Juan 17:17; 2 Tim. 3:16, 17

$ python3 -m linkture -r "Mat 17:17; Paul 3:16, 17" --full -x
['Matthew 17:17']


$ python3 -m linkture -cc 2
('01002001', '01002025')

$ python3 -m linkture -cv 31091
('66022021', '66022021')

$ python3 -m linkture -sv '01001001'
1

python3 -m linkture -sc '66022001'
1189


python3 -m linkture -r '2Ti 3:16, 17' --full -s '_'
2_Timothy_3:16,_17

Note: The serial verse options (-sv and -cv) do not count Psalm headings as separate verses.

Of course, you can pass a whole text file to parse and process using the -f in_file flag, instead of -r "references". And you can output to another text file (instead of the terminal) using -o out_file.

Unless you use -q, you will see in the terminal any out-of-range errors encountered while parsing. Of course, these entries will not be processed, but they will not affect the rest of the operation.


Script/import usage

Assume the text (short string or long document) you want to process is in the variable txt.

from linkture import Scriptures

s = Scriptures(language="English", translate="Spanish", form="full")


lst = s.list_scriptures(txt)
# returns a list of (valid) extracted scriptures in the desired language and format

lst = s.code_scriptures(txt)
# returns a list of BCV-range tuples (start, end)

html = s.link_scriptures(txt, prefix='<a href="http://mywebsite.com/', suffix='" class="b"')
# this will turn all references into HTML links

tagged = s.tag_scriptures(txt)
# tagged will contain your document with the translated references enclosed within double braces

new_txt = s.rewrite_scriptures(txt)
# the references will simply be rewritten in the desired language and format


i = s.serial_chapter_number(ch_bcv)
# returns the serial number (1-1189) of the chapter identified by the provided BCV-format string; verse digits irrelevant

i = s.serial_verse_number(vs_bcv)
# returns the serial number (1-31091) of the verse identified by the provided BCV-format string

ch_bcv = s.code_chapter(i)
# returns a BCV-format range string for the whole chapter indicated by the provided integer (1-1189)

vs_bcv = s.code_verse(i)
# returns a BCV-format range string for the verse indicated by the provided integer (1-31091)

Parameters:

  • language - source language for Scripture parsing
  • translate - language for Bible book name translation
  • form - output format of Bible book names
    • "full" for full name format (eg., "Genesis")
    • "standard" for standard abbreviation format (eg., "Gen.")
    • "official" for official abbreviation format (eg., "Ge")
    • None or not supplied - no re-write will be performed, unless translation is performed or linking (in which case, "full" is the default)
  • separator - character(s) to use instead of space (default) to separate the various segments of the scripture
  • upper - if True, outputs book names in UPPER CASE (False by default)
  • verbose - if True, show (in terminal) any out-of-range errors encountered while parsing (False by default)

Feedback

Feel free to get in touch and post any issues and suggestions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkture-2.6.4.tar.gz (274.7 kB view details)

Uploaded Source

Built Distribution

linkture-2.6.4-py3-none-any.whl (273.1 kB view details)

Uploaded Python 3

File details

Details for the file linkture-2.6.4.tar.gz.

File metadata

  • Download URL: linkture-2.6.4.tar.gz
  • Upload date:
  • Size: 274.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for linkture-2.6.4.tar.gz
Algorithm Hash digest
SHA256 d205a553b7721c24a2d3b1d03e19f0aec41ea7a533c3acf77d8644c3eb6bf8d9
MD5 40a2e7090621d5e9a4bffb2df6f587a8
BLAKE2b-256 4b5d675c0e8509e4ddc6182860cfe754403039328ccb5282837ef2dcf4959975

See more details on using hashes here.

File details

Details for the file linkture-2.6.4-py3-none-any.whl.

File metadata

  • Download URL: linkture-2.6.4-py3-none-any.whl
  • Upload date:
  • Size: 273.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for linkture-2.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7a0852fd6853c607cab2494304647461e1b7ee570fb9a8d34b530bc8e9e347a4
MD5 3dbc2d11f0cd7f1ab830be354d265b20
BLAKE2b-256 5189422260c074d636cbed8cf747232a8bcfee305436a0826bb5cd6cdc5c26c3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page