versiref 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- versiref-0.1.0/.gitignore +11 -0
- versiref-0.1.0/.python-version +1 -0
- versiref-0.1.0/.vscode/settings.json +12 -0
- versiref-0.1.0/CONVENTIONS.MD +4 -0
- versiref-0.1.0/DESIGN.md +88 -0
- versiref-0.1.0/LICENSE +21 -0
- versiref-0.1.0/PKG-INFO +127 -0
- versiref-0.1.0/README.md +101 -0
- versiref-0.1.0/pyproject.toml +66 -0
- versiref-0.1.0/src/versiref/__init__.py +21 -0
- versiref-0.1.0/src/versiref/bible_ref.py +427 -0
- versiref-0.1.0/src/versiref/data/book_names/en-cmos_long.json +83 -0
- versiref-0.1.0/src/versiref/data/book_names/en-cmos_short.json +85 -0
- versiref-0.1.0/src/versiref/data/book_names/en-sbl_abbreviations.json +92 -0
- versiref-0.1.0/src/versiref/data/book_names/en-sbl_names.json +92 -0
- versiref-0.1.0/src/versiref/data/book_names/it-cei_abbreviazioni.json +76 -0
- versiref-0.1.0/src/versiref/data/book_names/it-cei_nomi.json +76 -0
- versiref-0.1.0/src/versiref/data/versifications/eng.json +1937 -0
- versiref-0.1.0/src/versiref/data/versifications/lxx.json +2425 -0
- versiref-0.1.0/src/versiref/data/versifications/nabre.json +1532 -0
- versiref-0.1.0/src/versiref/data/versifications/nova-vulgata.json +2057 -0
- versiref-0.1.0/src/versiref/data/versifications/org.json +1790 -0
- versiref-0.1.0/src/versiref/data/versifications/rsc.json +1559 -0
- versiref-0.1.0/src/versiref/data/versifications/rso.json +1911 -0
- versiref-0.1.0/src/versiref/data/versifications/vulgata.json +2070 -0
- versiref-0.1.0/src/versiref/py.typed +0 -0
- versiref-0.1.0/src/versiref/ref_parser.py +578 -0
- versiref-0.1.0/src/versiref/ref_style.py +127 -0
- versiref-0.1.0/src/versiref/versification.py +135 -0
- versiref-0.1.0/test_all_versions.py +26 -0
- versiref-0.1.0/tests/__init__.py +1 -0
- versiref-0.1.0/tests/test_bible_ref.py +799 -0
- versiref-0.1.0/tests/test_parse_and_format.py +308 -0
- versiref-0.1.0/tests/test_ref_parser.py +353 -0
- versiref-0.1.0/tests/test_style.py +36 -0
- versiref-0.1.0/tests/test_versification.py +96 -0
- versiref-0.1.0/uv.lock +228 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mypy-type-checker.importStrategy": "fromEnvironment",
|
|
3
|
+
"mypy-type-checker.ignorePatterns": [
|
|
4
|
+
"build/*.py"
|
|
5
|
+
],
|
|
6
|
+
"python.testing.pytestArgs": [
|
|
7
|
+
"tests"
|
|
8
|
+
],
|
|
9
|
+
"python.testing.unittestEnabled": false,
|
|
10
|
+
"python.testing.pytestEnabled": true,
|
|
11
|
+
"ruff.configuration": "pyproject.toml"
|
|
12
|
+
}
|
versiref-0.1.0/DESIGN.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# VersiRef Design Document
|
|
2
|
+
|
|
3
|
+
VersiRef is a Python package for sophisticated parsing, manipulation, and printing of references to the Bible.
|
|
4
|
+
|
|
5
|
+
This design document was created prior to the implementation, and so may not fully correspond to it.
|
|
6
|
+
|
|
7
|
+
## SimpleBibleRef
|
|
8
|
+
|
|
9
|
+
An instance of `SimpleBibleRef` represents a sequence of verse ranges within a single book of the Bible.
|
|
10
|
+
These ranges are not necessarily in numeric order because the person who creates the citation may prefer a different order.
|
|
11
|
+
The class is naive in that it doesn't specify its versification (this is something like `datetime`'s naive classes, which don't specify a time zone).
|
|
12
|
+
In the simplest case, it designates a single chapter and verse, such as John 3:16.
|
|
13
|
+
More generally, each range contains a start chapter, start verse, start subverse, end chapter, end verse, and end subverse.
|
|
14
|
+
Each range also has `original_text: Optional[str]`: this is the text from which the range was parsed, if any.
|
|
15
|
+
The class stores a list of such ranges, a book ID, and the `original_text` from which the book ID was parsed.
|
|
16
|
+
Book IDs are the three-letter codes used by Paratext, e.g., "GEN", "1CO", or "JHN".
|
|
17
|
+
The start and end chapter numbers will almost always be the same, but the volume of data is probably not large enough to justify complicating the code by optimizing for that.
|
|
18
|
+
Similarly, subverse divisions (e.g., "a" or "d") will often not be used: when there is none, the subverse will be an empty string.
|
|
19
|
+
We can just store all six values for each range, even in the trivial case where the range is a single verse.
|
|
20
|
+
Chapter and verse numbers are `int`s: on careful consideration, we never need to use strings for either.
|
|
21
|
+
Although some Bible translations use letters for "chapter numbers" (e.g., Greek Esther in Rahlfs and NAB), we don't need to support that explicitly: Paratext's scheme represents these as numbered chapters with a different book name (ESG instead of EST).
|
|
22
|
+
The rare case of verse numbers like "4kk" can be represented as verse 4, subverse "kk": that is how it would parse anyway.
|
|
23
|
+
As a special case, a `SimpleBibleRef` with an empty list of ranges refers to the entire book.
|
|
24
|
+
The constructor takes a book ID and an `original_text`, which defaults to `None`.
|
|
25
|
+
|
|
26
|
+
## BibleRef
|
|
27
|
+
|
|
28
|
+
An instance of `BibleRef` represents a sequence of verse ranges within a one or more books of the Bible.
|
|
29
|
+
It holds an array of `SimpleBibleRef` and the `Versification` they use.
|
|
30
|
+
|
|
31
|
+
## Versification
|
|
32
|
+
|
|
33
|
+
An instance of `Versification` represents a way of dividing the text of the Bible into chapters and verses.
|
|
34
|
+
Versifications are defined by JSON data that is loaded from a file when an instance is created.
|
|
35
|
+
Alternatively, the JSON data could be converted to Python data and stored as constants in code.
|
|
36
|
+
The `last_verse(book, chapter)` method returns the integer number of the last verse of the given chapter of the given book.
|
|
37
|
+
If the book is unknown or the chapter does not exist, it returns -1.
|
|
38
|
+
An initial, trivial implementation will not load a data file and will simply return 99 from `last_verse()` regardless of its arguments.
|
|
39
|
+
Support for mapping verses between versifications can be added at a later stage.
|
|
40
|
+
|
|
41
|
+
For versification data, we can use JSON files from a [UBSCAP GitHub repo](https://github.com/ubsicap/versification_json).
|
|
42
|
+
These are under an MIT license.
|
|
43
|
+
As the README notes, some of the files contain errors: there are mappings from verses that do not exist according to the max verse counts.
|
|
44
|
+
However, it seems the best starting point available, and those known errors will be harmless because such mappings will never be applied.
|
|
45
|
+
There's a JSON schema in the repo that can be used for validation.
|
|
46
|
+
The `maxVerses` property of the top-level object contains the data `last_verse()` must return.
|
|
47
|
+
|
|
48
|
+
The JSON files have data for Paratext's seven standard versifications.
|
|
49
|
+
Mappings are defined relative to the mapping called "Original" (`org.json`) for lack of a better name: This uses the BHS OT, the UBS GNT NT, and the "Catholic" deuterocanon.
|
|
50
|
+
|
|
51
|
+
It would not be hard to derive `maxVerses` and `excludedVerses` data for specific Bibles from verse lists exported from Accordance.
|
|
52
|
+
Mappings for these Bibles are an open question.
|
|
53
|
+
|
|
54
|
+
### Mapping verses between versifications
|
|
55
|
+
|
|
56
|
+
This would have to be done one range at a time, mapping the start and end of each.
|
|
57
|
+
When mapping a range start, if the location maps to a range, we pick the start of the range.
|
|
58
|
+
When mapping a range end, if the location maps to a range, we pick the end of the range.
|
|
59
|
+
For example, if 1KI 18:33 maps to 1KI 18:33-34 and we are mapping a range that starts at 1KI 18:33, then the mapped range starts at 1KI 18:33.
|
|
60
|
+
But if we are mapping a range that ends at 1KI 18:33, then the mapped range ends at 1KI 18:34.
|
|
61
|
+
However, we might not at first need code to handle the case where a location maps to a range, since it seems Paratext doesn't handle that. Consequently, its files don't define such mappings, even though there are cases in which they ought to be used.
|
|
62
|
+
|
|
63
|
+
## Style
|
|
64
|
+
|
|
65
|
+
A `Style` defines how a `SimpleBibleRef` or `BibleRef` is converted to a string and how strings are parsed to produce these classes.
|
|
66
|
+
|
|
67
|
+
* `names`: maps Bible book IDs to string abbreviations or to full names, depending on the style.
|
|
68
|
+
* `chapter_verse_separator`: Separates chapter number from verse ranges Defaults to ":".
|
|
69
|
+
* `verse_range_separator`: Separates ranges of verses in a single chapter. Defaults to ", ".
|
|
70
|
+
* `chapter_separator`: Defaults to "; ".
|
|
71
|
+
* `recognized_names`: maps abbreviations and/or full names to Bible book IDs. For flexibility in parsing, this typically recognizes additional abbreviations beyond those used in `names`. It defaults to the inverse of `names`.
|
|
72
|
+
|
|
73
|
+
### Named sets of book names/abbreviations
|
|
74
|
+
|
|
75
|
+
We need to have a way of supplying named sets of book names and book name abbreviations, so users can select, e.g., short SBL abbreviations.
|
|
76
|
+
These sets are simply dictionaries, but perhaps we need to store them in files or allow users to define their own set of abbreviations in a file.
|
|
77
|
+
|
|
78
|
+
### Bible IDs that require special handling
|
|
79
|
+
|
|
80
|
+
* PSA: we need to allow for both a singular and a plural form. The latter can be coded in abbreviation lists as PSAS, e.g., `"PSA": "Psalm", "PSAS": "Psalms"
|
|
81
|
+
* PS2: this is Psalm 151. It uses the PSA abbreviation (or PSAS when referenced with other psalms). Any abbreviation defined for PS2 will be ignored. Perhaps we should issue a warning if it's defined.
|
|
82
|
+
* ESG: this is Greek portions of Esther. Special handling may be required when it uses the same name as EST but letters for chapters (e.g., NABRE).
|
|
83
|
+
|
|
84
|
+
## RefParser
|
|
85
|
+
|
|
86
|
+
The constructor takes a `Style` and builds a PEG parser that recognizes Bible references in that style.
|
|
87
|
+
Whitespace is generally ignored by the parser (default for `pyparser`).
|
|
88
|
+
Various methods support parsing a whole string to a `SimpleBibleRef` or `BibleRef`, scanning a long string for references, and transforming a long string (e.g., to tag references).
|
versiref-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Michael F. Polis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
versiref-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: versiref
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A package for sophisticated parsing, manipulation, and printing of references to the Bible
|
|
5
|
+
Project-URL: Homepage, https://github.com/fiapps/versiref
|
|
6
|
+
Project-URL: Issues, https://github.com/fiapps/versiref/issues
|
|
7
|
+
Author-email: "Fr. John Lawrence M. Polis" <emptier-sank-dose@duck.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Religion
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Religion
|
|
22
|
+
Classifier: Topic :: Text Processing
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: pyparsing>=3.2.3
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# VersiRef
|
|
28
|
+
|
|
29
|
+
VersiRef is a Python package for sophisticated parsing, manipulation, and printing of references to the Bible.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Parse and manipulate Bible references.
|
|
34
|
+
- Support for different versification systems (e.g., original language \[BHS + UBS GNT\], "English," LXX, Vulgate).
|
|
35
|
+
- Query information about chapters and verses in different books of the Bible.
|
|
36
|
+
|
|
37
|
+
## Overview of `versiref` classes
|
|
38
|
+
|
|
39
|
+
- `BibleRef` represents a sequence of verse ranges within one or more books of the Bible.
|
|
40
|
+
- It has a `Versification` and a list of `SimpleBibleRef`s.
|
|
41
|
+
- `Versification` represents a division of the Bible into chapters and verses. Different texts of the Bible do this differently.
|
|
42
|
+
- `SimpleBibleRef` represents a sequence of verse ranges within a single book of the Bible.
|
|
43
|
+
- It can be used independently of a `BibleRef`, but since it has no `Versification`, you need to supply a `Versification` for all operations that require one.
|
|
44
|
+
- It contains a list of `VerseRange`s: this is a data class not intended to be used independently.
|
|
45
|
+
- `RefStyle` defines separators and book names or abbreviations to use in formatting or parsing a reference.
|
|
46
|
+
- This gives the package the versatility to handle different styles and languages.
|
|
47
|
+
- `RefParser` creates PEG parsers based on a `RefStyle` and `Versification`.
|
|
48
|
+
- These can be used to parse a single reference or to find all references in a long string, e.g., the content of a text file.
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
### Convert references from one style to another
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from pyparsing import ParseException
|
|
56
|
+
from versiref import RefParser, RefStyle, standard_names, Versification
|
|
57
|
+
|
|
58
|
+
def parse_reference(reference: str) -> None:
|
|
59
|
+
"""Parse argument and print result."""
|
|
60
|
+
# Expect SBL abbreviations in the input
|
|
61
|
+
sbl_abbrevs = standard_names("en-sbl_abbreviations")
|
|
62
|
+
sbl_style = RefStyle(names=sbl_abbrevs)
|
|
63
|
+
# Use typical versification for English Bibles
|
|
64
|
+
versification = Versification.named("eng")
|
|
65
|
+
# Build parser for style
|
|
66
|
+
parser = RefParser(sbl_style, versification)
|
|
67
|
+
# Use Italian CEI Bible style for output
|
|
68
|
+
cei_abbrevs = standard_names("it-cei_abbreviazioni")
|
|
69
|
+
cei_style = RefStyle(names=cei_abbrevs, chapter_verse_separator=",", verse_range_separator=".")
|
|
70
|
+
try:
|
|
71
|
+
ref = parser.parse(reference, silent=False)
|
|
72
|
+
# Check whether it refers to verse ranges that exist
|
|
73
|
+
if not ref.is_valid():
|
|
74
|
+
print(f"Warning: {reference} is not a valid reference.")
|
|
75
|
+
print(ref.format(cei_style))
|
|
76
|
+
except ParseException as e:
|
|
77
|
+
print(f"Could not parse reference: {reference}")
|
|
78
|
+
print(e)
|
|
79
|
+
|
|
80
|
+
# Prints "Gv 7,53–8,11"
|
|
81
|
+
parse_reference("John 7:53–8:11")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Look for references in a string
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from versiref import RefParser, RefStyle, Versification, standard_names
|
|
88
|
+
|
|
89
|
+
def scan_string(content: str) -> None:
|
|
90
|
+
"""Count and print the Bible references in content."""
|
|
91
|
+
# Use SBL abbreviations
|
|
92
|
+
sbl_abbrevs = standard_names("en-sbl_abbreviations")
|
|
93
|
+
style = RefStyle(names=sbl_abbrevs)
|
|
94
|
+
# But also recognize abbreviations from the Chicago Manual of Style
|
|
95
|
+
style.also_recognize("en-cmos_short")
|
|
96
|
+
# Use typical versification for English Bibles
|
|
97
|
+
versification = Versification.named("eng")
|
|
98
|
+
# Build parser for style
|
|
99
|
+
parser = RefParser(style, versification)
|
|
100
|
+
count = 0
|
|
101
|
+
for ref, start, end in parser.scan_string(content):
|
|
102
|
+
# Check for out-of-range chapter or verse
|
|
103
|
+
if not ref.is_valid():
|
|
104
|
+
print(f"Warning: {ref.format(style)} is not a valid reference.")
|
|
105
|
+
else:
|
|
106
|
+
# Print in SBL style
|
|
107
|
+
print(ref.format(style))
|
|
108
|
+
count += 1
|
|
109
|
+
print(f"Found {count} references.")
|
|
110
|
+
|
|
111
|
+
text = """
|
|
112
|
+
Today's readings are Acts 2:1-11; Ps 104:1,24,29-30,31,34; 1 Cor 12:3b-7,12-13; Jn 20:19-23.
|
|
113
|
+
The prophecy in Is 7:10-14 is important background for Lk 1:26-38.
|
|
114
|
+
The Septuagint has a Ps 118:120, but English Bibles don't.
|
|
115
|
+
"""
|
|
116
|
+
scan_string(text)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Output:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
Acts 2:1–11; Ps 104:1, 24, 29–30, 31, 34; 1 Cor 12:3b–7, 12–13; John 20:19–23
|
|
123
|
+
Isa 7:10–14
|
|
124
|
+
Luke 1:26–38
|
|
125
|
+
Warning: Ps 118:120 is not a valid reference.
|
|
126
|
+
Found 4 references.
|
|
127
|
+
```
|
versiref-0.1.0/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# VersiRef
|
|
2
|
+
|
|
3
|
+
VersiRef is a Python package for sophisticated parsing, manipulation, and printing of references to the Bible.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Parse and manipulate Bible references.
|
|
8
|
+
- Support for different versification systems (e.g., original language \[BHS + UBS GNT\], "English," LXX, Vulgate).
|
|
9
|
+
- Query information about chapters and verses in different books of the Bible.
|
|
10
|
+
|
|
11
|
+
## Overview of `versiref` classes
|
|
12
|
+
|
|
13
|
+
- `BibleRef` represents a sequence of verse ranges within one or more books of the Bible.
|
|
14
|
+
- It has a `Versification` and a list of `SimpleBibleRef`s.
|
|
15
|
+
- `Versification` represents a division of the Bible into chapters and verses. Different texts of the Bible do this differently.
|
|
16
|
+
- `SimpleBibleRef` represents a sequence of verse ranges within a single book of the Bible.
|
|
17
|
+
- It can be used independently of a `BibleRef`, but since it has no `Versification`, you need to supply a `Versification` for all operations that require one.
|
|
18
|
+
- It contains a list of `VerseRange`s: this is a data class not intended to be used independently.
|
|
19
|
+
- `RefStyle` defines separators and book names or abbreviations to use in formatting or parsing a reference.
|
|
20
|
+
- This gives the package the versatility to handle different styles and languages.
|
|
21
|
+
- `RefParser` creates PEG parsers based on a `RefStyle` and `Versification`.
|
|
22
|
+
- These can be used to parse a single reference or to find all references in a long string, e.g., the content of a text file.
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
### Convert references from one style to another
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from pyparsing import ParseException
|
|
30
|
+
from versiref import RefParser, RefStyle, standard_names, Versification
|
|
31
|
+
|
|
32
|
+
def parse_reference(reference: str) -> None:
|
|
33
|
+
"""Parse argument and print result."""
|
|
34
|
+
# Expect SBL abbreviations in the input
|
|
35
|
+
sbl_abbrevs = standard_names("en-sbl_abbreviations")
|
|
36
|
+
sbl_style = RefStyle(names=sbl_abbrevs)
|
|
37
|
+
# Use typical versification for English Bibles
|
|
38
|
+
versification = Versification.named("eng")
|
|
39
|
+
# Build parser for style
|
|
40
|
+
parser = RefParser(sbl_style, versification)
|
|
41
|
+
# Use Italian CEI Bible style for output
|
|
42
|
+
cei_abbrevs = standard_names("it-cei_abbreviazioni")
|
|
43
|
+
cei_style = RefStyle(names=cei_abbrevs, chapter_verse_separator=",", verse_range_separator=".")
|
|
44
|
+
try:
|
|
45
|
+
ref = parser.parse(reference, silent=False)
|
|
46
|
+
# Check whether it refers to verse ranges that exist
|
|
47
|
+
if not ref.is_valid():
|
|
48
|
+
print(f"Warning: {reference} is not a valid reference.")
|
|
49
|
+
print(ref.format(cei_style))
|
|
50
|
+
except ParseException as e:
|
|
51
|
+
print(f"Could not parse reference: {reference}")
|
|
52
|
+
print(e)
|
|
53
|
+
|
|
54
|
+
# Prints "Gv 7,53–8,11"
|
|
55
|
+
parse_reference("John 7:53–8:11")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Look for references in a string
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from versiref import RefParser, RefStyle, Versification, standard_names
|
|
62
|
+
|
|
63
|
+
def scan_string(content: str) -> None:
|
|
64
|
+
"""Count and print the Bible references in content."""
|
|
65
|
+
# Use SBL abbreviations
|
|
66
|
+
sbl_abbrevs = standard_names("en-sbl_abbreviations")
|
|
67
|
+
style = RefStyle(names=sbl_abbrevs)
|
|
68
|
+
# But also recognize abbreviations from the Chicago Manual of Style
|
|
69
|
+
style.also_recognize("en-cmos_short")
|
|
70
|
+
# Use typical versification for English Bibles
|
|
71
|
+
versification = Versification.named("eng")
|
|
72
|
+
# Build parser for style
|
|
73
|
+
parser = RefParser(style, versification)
|
|
74
|
+
count = 0
|
|
75
|
+
for ref, start, end in parser.scan_string(content):
|
|
76
|
+
# Check for out-of-range chapter or verse
|
|
77
|
+
if not ref.is_valid():
|
|
78
|
+
print(f"Warning: {ref.format(style)} is not a valid reference.")
|
|
79
|
+
else:
|
|
80
|
+
# Print in SBL style
|
|
81
|
+
print(ref.format(style))
|
|
82
|
+
count += 1
|
|
83
|
+
print(f"Found {count} references.")
|
|
84
|
+
|
|
85
|
+
text = """
|
|
86
|
+
Today's readings are Acts 2:1-11; Ps 104:1,24,29-30,31,34; 1 Cor 12:3b-7,12-13; Jn 20:19-23.
|
|
87
|
+
The prophecy in Is 7:10-14 is important background for Lk 1:26-38.
|
|
88
|
+
The Septuagint has a Ps 118:120, but English Bibles don't.
|
|
89
|
+
"""
|
|
90
|
+
scan_string(text)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Output:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Acts 2:1–11; Ps 104:1, 24, 29–30, 31, 34; 1 Cor 12:3b–7, 12–13; John 20:19–23
|
|
97
|
+
Isa 7:10–14
|
|
98
|
+
Luke 1:26–38
|
|
99
|
+
Warning: Ps 118:120 is not a valid reference.
|
|
100
|
+
Found 4 references.
|
|
101
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "versiref"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A package for sophisticated parsing, manipulation, and printing of references to the Bible"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Fr. John Lawrence M. Polis", email = "emptier-sank-dose@duck.com" }
|
|
8
|
+
]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Intended Audience :: Religion",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.9",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Topic :: Religion",
|
|
22
|
+
"Topic :: Text Processing",
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.9"
|
|
25
|
+
license = "MIT"
|
|
26
|
+
license-files = ["LICEN[CS]E*"]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"pyparsing>=3.2.3",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/fiapps/versiref"
|
|
33
|
+
Issues = "https://github.com/fiapps/versiref/issues"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/versiref"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel.sources]
|
|
43
|
+
"data" = "src/versiref/data"
|
|
44
|
+
|
|
45
|
+
[tool.mypy]
|
|
46
|
+
strict = true
|
|
47
|
+
exclude = [
|
|
48
|
+
'build',
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["D"]
|
|
53
|
+
ignore = ["D203", "D213"]
|
|
54
|
+
|
|
55
|
+
[[tool.uv.index]]
|
|
56
|
+
name = "testpypi"
|
|
57
|
+
url = "https://test.pypi.org/simple/"
|
|
58
|
+
publish-url = "https://test.pypi.org/legacy/"
|
|
59
|
+
explicit = true
|
|
60
|
+
|
|
61
|
+
[dependency-groups]
|
|
62
|
+
dev = [
|
|
63
|
+
"mypy>=1.15.0",
|
|
64
|
+
"pytest>=8.3.5",
|
|
65
|
+
"ruff>=0.11.4",
|
|
66
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""versiref can parse, manipulate, and format references to Bible verses.
|
|
2
|
+
|
|
3
|
+
It is versatile in that it can handle complex references, different
|
|
4
|
+
versifications, and it is flexible about the format is parses and the output it
|
|
5
|
+
generates.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from versiref.bible_ref import BibleRef, SimpleBibleRef, VerseRange
|
|
9
|
+
from versiref.ref_parser import RefParser
|
|
10
|
+
from versiref.ref_style import RefStyle, standard_names
|
|
11
|
+
from versiref.versification import Versification
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"BibleRef",
|
|
15
|
+
"SimpleBibleRef",
|
|
16
|
+
"VerseRange",
|
|
17
|
+
"RefParser",
|
|
18
|
+
"RefStyle",
|
|
19
|
+
"Versification",
|
|
20
|
+
"standard_names",
|
|
21
|
+
]
|