Skip to content

Commit 3d263a1

Browse files
selah-aweandreverence[bot]selah-aweandreverence[bot]jontsai
authored
feat: normalize Bible book aliases (#13)
## Summary - add normalized Bible book alias resolution for punctuation, spacing, case, and ordinal variants - support unambiguous generated prefixes while preserving explicit aliases first - expose conservative fuzzy alias matching for callers that want typo correction only when the alias resolves to one canonical book - keep `apps/bible/constants/aliases.py` constants-focused by moving Bible-specific alias helpers to `htk.apps.bible.utils.references` - keep the existing numpy-backed `htk.utils.text.algorithms.levenshtein_distance()` implementation and add docstring/type hints - update `BibleBook.from_reference()` and the Bible constants docs to use the normalized resolver - expand the alias table with common unambiguous Bible book abbreviations used across SBL-style references and online Bible-study tools ## Abbreviation coverage notes Added common missing forms such as: - OT: `Exod`, `Deu`, `1 Kgs`, `2 Kgs`, `1 Chron`, `2 Chron`, `Psa`, `Pss`, `Prv`, `Qoh`, `Cant`, `Sng`, `Ezk`, `Dn`, `Zc` - NT: `Jhn`, `Joh`, `Rm`, `1 Thes`, `1 Ts`, `1 Ti`, `Phile`, `1 Pt`, `1 Jo`, `Rv` Intentionally left very short or ambiguous forms unresolved, including `Jo`, `Ju`, `Ma`, `Ze`, `1 C`, and `2 T`. ## Verification - `python3 -m compileall -q htk/apps/bible/constants/aliases.py htk/apps/bible/models.py htk/apps/bible/utils/references.py htk/utils/text/algorithms.py tests/test_bible_book_aliases.py tests/test_bible_book_correction.py` - `git diff --check` - exact alias collision script: no normalized alias collisions; confirmed `Jhn`, `1 Kgs`, `Pss`, `Prv`, `Qoh`, `Canticles`, and `Rv` resolve, while `Jo`, `1 C`, `2 T`, and `Ze` do not ## Local test note - `python3 -m unittest tests.test_bible_book_aliases tests.test_bible_book_correction` is blocked in this bare shell by missing local HTK/runtime dependencies: importing `htk.apps.bible.utils.references` triggers `htk.apps.bible.utils.__init__` → `htk.utils.__init__` → `pytz`, which is not installed here. Full app-suite verification should run in the project venv/CI. Co-authored-by: Jonathan Tsai <jontsai@users.noreply.github.com> --------- Co-authored-by: selah-aweandreverence[bot] <2972811+selah-aweandreverence[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tsai <jontsai@users.noreply.github.com> Co-authored-by: selah-aweandreverence[bot] <264603484+selah-aweandreverence[bot]@users.noreply.github.com>
1 parent 06c37f0 commit 3d263a1

5 files changed

Lines changed: 340 additions & 19 deletions

File tree

apps/bible/constants/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ This module provides constants for Bible book metadata, aliases, and translation
1111
- **`BIBLE_BOOKS`** - List of all 66 canonical Bible book names
1212
- **`BIBLE_BOOKS_DATA`** - List of dicts with book metadata: `name` and `chapters` count
1313
- **`BIBLE_BOOKS_ALIASES`** - Dict mapping book names to lists of common abbreviations (e.g., 'Gen', 'Matt')
14-
- **`BIBLE_BOOKS_ALIAS_MAPPINGS`** - Dict mapping all aliases and case variants to canonical book names
14+
- **`BIBLE_BOOKS_ALIAS_MAPPINGS`** - Legacy dict mapping aliases and case variants to canonical book names
15+
- **`resolve_bible_book_alias()`** - Resolves canonical book names, aliases, punctuation/spacing variants, and unambiguous prefixes to a canonical book name
16+
- **`match_bible_book_alias()`** - Returns match metadata for exact, prefix, or optional fuzzy alias matches when the match is unique
1517

1618
### Model References
1719

@@ -59,11 +61,13 @@ print(f"{genesis['name']}: {genesis['chapters']} chapters")
5961
### Resolve Book Aliases
6062

6163
```python
62-
from htk.apps.bible.constants import BIBLE_BOOKS_ALIAS_MAPPINGS
64+
from htk.apps.bible.utils.references import resolve_bible_book_alias
6365

64-
# Find canonical name from abbreviation
65-
canonical = BIBLE_BOOKS_ALIAS_MAPPINGS['Matt'] # Returns 'Matthew'
66-
canonical = BIBLE_BOOKS_ALIAS_MAPPINGS['matt'] # Case-insensitive
66+
# Find canonical name from abbreviation, spacing/case variants, or safe prefix
67+
canonical = resolve_bible_book_alias('Matt.') # Returns 'Matthew'
68+
canonical = resolve_bible_book_alias('I Jn') # Returns '1 John'
69+
canonical = resolve_bible_book_alias('Deu') # Returns 'Deuteronomy'
70+
ambiguous = resolve_bible_book_alias('Jo') # Returns None
6771
```
6872

6973
### Configure Models

apps/bible/constants/aliases.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,95 @@
44
'Genesis' : [
55
'Gen',
66
'Gn',
7+
'Ge',
78
],
89
'Exodus' : [
910
'Ex',
1011
'Exo',
12+
'Exod',
1113
],
1214
'Leviticus' : [
1315
'Lev',
1416
'Lv',
1517
],
1618
'Numbers' : [
1719
'Num',
20+
'Nu',
21+
'Nm',
1822
],
1923
'Deuteronomy' : [
2024
'Deut',
2125
'Dt',
26+
'Deu',
2227
],
2328
'Joshua' : [
2429
'Jos',
2530
'Josh',
31+
'Jsh',
2632
],
2733
'Judges' : [
2834
'Jdg',
2935
'Judg',
3036
'Judge',
37+
'Jg',
38+
'Jgs',
3139
],
3240
'Ruth' : [
3341
'Rut',
42+
'Ru',
43+
'Rth',
3444
],
3545
'1 Samuel' : [
3646
'1Sam',
3747
'1 Sam',
48+
'1Sa',
49+
'1 Sa',
50+
'1Sm',
51+
'1 Sm',
3852
],
3953
'2 Samuel' : [
4054
'2Sam',
4155
'2 Sam',
56+
'2Sa',
57+
'2 Sa',
58+
'2Sm',
59+
'2 Sm',
4260
],
4361
'1 Kings' : [
4462
'1Kin',
4563
'1 Kin',
64+
'1Ki',
65+
'1 Ki',
66+
'1Kgs',
67+
'1 Kgs',
68+
'1Kg',
69+
'1 Kg',
4670
],
4771
'2 Kings' : [
4872
'2Kin',
4973
'2 Kin',
74+
'2Ki',
75+
'2 Ki',
76+
'2Kgs',
77+
'2 Kgs',
78+
'2Kg',
79+
'2 Kg',
5080
],
5181
'1 Chronicles' : [
5282
'1Chr',
5383
'1 Chr',
84+
'1Ch',
85+
'1 Ch',
86+
'1Chron',
87+
'1 Chron',
5488
],
5589
'2 Chronicles' : [
5690
'2Chr',
5791
'2 Chr',
92+
'2Ch',
93+
'2 Ch',
94+
'2Chron',
95+
'2 Chron',
5896
],
5997
'Ezra' : [
6098
'Ezr',
@@ -64,49 +102,72 @@
64102
],
65103
'Esther' : [
66104
'Esth',
105+
'Est',
67106
],
68107
'Job' : [
69108
'Job',
109+
'Jb',
70110
],
71111
'Psalms' : [
72112
'Ps',
73113
'Psalm',
114+
'Psa',
115+
'Pss',
74116
],
75117
'Proverbs' : [
76118
'Pro',
77119
'Prov',
120+
'Pr',
121+
'Prv',
78122
],
79123
'Ecclesiastes' : [
80124
'Eccl',
125+
'Ecc',
126+
'Ec',
127+
'Qoh',
81128
],
82129
'Song of Solomon' : [
83130
'Song',
84131
'Song of Songs',
85132
'Songs',
133+
'Cant',
134+
'Canticles',
135+
'Sng',
136+
'SoS',
137+
'Song Sol',
86138
],
87139
'Isaiah' : [
88140
'Is',
89141
'Isa',
90142
],
91143
'Jeremiah' : [
92144
'Jer',
145+
'Je',
146+
'Jr',
93147
],
94148
'Lamentations' : [
95149
'Lam',
150+
'La',
151+
'Lm',
96152
],
97153
'Ezekiel' : [
98154
'Eze',
99155
'Ezek',
156+
'Ezk',
100157
],
101158
'Daniel' : [
102159
'Dan',
160+
'Da',
161+
'Dn',
103162
],
104163
'Hosea' : [
105164
'Hos',
165+
'Ho',
106166
],
107167
'Joel' : [
108168
'Jl',
109169
'Joel',
170+
'Joe',
110171
],
111172
'Amos' : [
112173
'Am',
@@ -120,70 +181,92 @@
120181
],
121182
'Jonah' : [
122183
'Jon',
184+
'Jnh',
123185
],
124186
'Micah' : [
125187
'Mic',
188+
'Mi',
126189
],
127190
'Nahum' : [
128191
'Nah',
192+
'Na',
129193
],
130194
'Habakkuk' : [
131195
'Hab',
132196
],
133197
'Zephaniah' : [
134198
'Zep',
135199
'Zeph',
200+
'Zp',
136201
],
137202
'Haggai' : [
138203
'Hag',
204+
'Hg',
139205
],
140206
'Zechariah' : [
141207
'Zec',
142208
'Zech',
209+
'Zc',
143210
],
144211
'Malachi' : [
145212
'Mal',
213+
'Ml',
146214
],
147215
'Matthew' : [
216+
'Mt',
148217
'Mat',
149218
'Matt',
150219
],
151220
'Mark' : [
152221
'Mk',
222+
'Mar',
223+
'Mrk',
153224
],
154225
'Luke' : [
226+
'Lk',
155227
'Luk',
228+
'Lu',
156229
],
157230
'John' : [
158231
'Jn',
232+
'Joh',
233+
'Jhn',
159234
],
160235
'Acts' : [
236+
'Ac',
161237
'Act',
162238
],
163239
'Romans' : [
240+
'Ro',
164241
'Rom',
165242
'Roms',
243+
'Rm',
166244
],
167245
'1 Corinthians' : [
246+
'1Co',
168247
'1Cor',
169248
'1 Cor',
170249
'1 Corin',
171250
'1 Corinth',
172251
],
173252
'2 Corinthians' : [
253+
'2Co',
174254
'2Cor',
175255
'2 Cor',
176256
'2 Corin',
177257
'2 Corinth',
178258
],
179259
'Galatians' : [
180260
'Gal',
261+
'Ga',
181262
],
182263
'Ephesians' : [
183264
'Eph',
265+
'Ep',
184266
],
185267
'Philippians' : [
186268
'Phil',
269+
'Php',
187270
],
188271
'Colossians' : [
189272
'Col',
@@ -194,66 +277,103 @@
194277
'1Thess',
195278
'1 Th',
196279
'1 Thess',
280+
'1Thes',
281+
'1 Thes',
282+
'1Ts',
283+
'1 Ts',
197284
],
198285
'2 Thessalonians' : [
199286
'2Th',
200287
'2Thess',
201288
'2 Th',
202289
'2 Thess',
290+
'2Thes',
291+
'2 Thes',
292+
'2Ts',
293+
'2 Ts',
203294
],
204295
'1 Timothy' : [
205296
'1Tim',
206297
'1 Tim',
298+
'1Ti',
299+
'1 Ti',
207300
],
208301
'2 Timothy' : [
209302
'2Tim',
210303
'2 Tim',
304+
'2Ti',
305+
'2 Ti',
211306
],
212307
'Titus' : [
213308
'Tit',
309+
'Ti',
214310
],
215311
'Philemon' : [
216312
'Philem',
217313
'Phlm',
218314
'Phm',
315+
'Phile',
219316
],
220317
'Hebrews' : [
221318
'Heb',
222319
],
223320
'James' : [
321+
'Jas',
224322
'Jam',
323+
'Ja',
324+
'Jm',
225325
],
226326
'1 Peter' : [
327+
'1Pe',
227328
'1Pet',
228329
'1 Pet',
330+
'1Pt',
331+
'1 Pt',
229332
],
230333
'2 Peter' : [
334+
'2Pe',
231335
'2Pet',
232336
'2 Pet',
337+
'2Pt',
338+
'2 Pt',
233339
],
234340
'1 John' : [
235341
'1Jn',
236342
'1John',
237343
'1 Jn',
344+
'1Jo',
345+
'1 Jo',
346+
'1Jhn',
347+
'1 Jhn',
238348
],
239349
'2 John' : [
240350
'2Jn',
241351
'2John',
242352
'2 Jn',
353+
'2Jo',
354+
'2 Jo',
355+
'2Jhn',
356+
'2 Jhn',
243357
],
244358
'3 John' : [
245359
'3Jn',
246360
'3John',
247361
'3 Jn',
362+
'3Jo',
363+
'3 Jo',
364+
'3Jhn',
365+
'3 Jhn',
248366
],
249367
'Jude' : [
250368
'Jud',
251369
],
252370
'Revelation' : [
253371
'Rev',
372+
'Rv',
254373
],
255374
}
256375

376+
257377
# Programmatically build mappings from common Bible book abbreviations or aliases to canonical name, including uppercase and lowercase variants
258378
BIBLE_BOOKS_ALIAS_MAPPINGS = {}
259379

0 commit comments

Comments
 (0)