Files
kjvstudy.org/kjvstudy_org/utils/books.py
T
kennethreitz 9def1c4ce9 Fix Song of Solomon book name mapping (reverse direction)
Correct the book name normalization to map FROM "Song of Solomon"
TO "Solomon's Song" (the name used in verses-1769.json).

Changes:
- Reverse all Song mappings to point to "Solomon's Song"
- Update OT_BOOKS to use "Solomon's Song" (matching verses file)
- Map "Song of Solomon", "Song of Songs", and "Canticles" → "Solomon's Song"

This fixes the 404 error on /book/Song%20of%20Solomon by ensuring
that alternative names redirect to the canonical verses file name.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 09:25:52 -05:00

252 lines
6.6 KiB
Python

"""Book name normalization and categorization utilities."""
from typing import Optional
# Old Testament books
OT_BOOKS = [
'Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuteronomy',
'Joshua', 'Judges', 'Ruth', '1 Samuel', '2 Samuel',
'1 Kings', '2 Kings', '1 Chronicles', '2 Chronicles',
'Ezra', 'Nehemiah', 'Esther', 'Job', 'Psalms', 'Proverbs',
'Ecclesiastes', "Solomon's Song", 'Isaiah', 'Jeremiah',
'Lamentations', 'Ezekiel', 'Daniel', 'Hosea', 'Joel', 'Amos',
'Obadiah', 'Jonah', 'Micah', 'Nahum', 'Habakkuk', 'Zephaniah',
'Haggai', 'Zechariah', 'Malachi'
]
# New Testament books
NT_BOOKS = [
'Matthew', 'Mark', 'Luke', 'John', 'Acts',
'Romans', '1 Corinthians', '2 Corinthians', 'Galatians', 'Ephesians',
'Philippians', 'Colossians', '1 Thessalonians', '2 Thessalonians',
'1 Timothy', '2 Timothy', 'Titus', 'Philemon',
'Hebrews', 'James', '1 Peter', '2 Peter',
'1 John', '2 John', '3 John', 'Jude', 'Revelation'
]
# Comprehensive book name abbreviations and variations
BOOK_ABBREVIATIONS = {
# Psalm/Psalms
"Psalm": "Psalms",
# Roman numerals to Arabic numerals
"I Samuel": "1 Samuel",
"II Samuel": "2 Samuel",
"I Kings": "1 Kings",
"II Kings": "2 Kings",
"I Chronicles": "1 Chronicles",
"II Chronicles": "2 Chronicles",
"I Corinthians": "1 Corinthians",
"II Corinthians": "2 Corinthians",
"I Thessalonians": "1 Thessalonians",
"II Thessalonians": "2 Thessalonians",
"I Timothy": "1 Timothy",
"II Timothy": "2 Timothy",
"I Peter": "1 Peter",
"II Peter": "2 Peter",
"I John": "1 John",
"II John": "2 John",
"III John": "3 John",
# Full word numbers to Arabic numerals
"First Samuel": "1 Samuel",
"Second Samuel": "2 Samuel",
"First Kings": "1 Kings",
"Second Kings": "2 Kings",
"First Chronicles": "1 Chronicles",
"Second Chronicles": "2 Chronicles",
"First Corinthians": "1 Corinthians",
"Second Corinthians": "2 Corinthians",
"First Thessalonians": "1 Thessalonians",
"Second Thessalonians": "2 Thessalonians",
"First Timothy": "1 Timothy",
"Second Timothy": "2 Timothy",
"First Peter": "1 Peter",
"Second Peter": "2 Peter",
"First John": "1 John",
"Second John": "2 John",
"Third John": "3 John",
# Alternative names (map to the name used in verses-1769.json)
"Song of Solomon": "Solomon's Song",
"Song of Songs": "Solomon's Song",
"Canticles": "Solomon's Song",
# Common abbreviations - Old Testament
"Gen": "Genesis",
"Ge": "Genesis",
"Exo": "Exodus",
"Ex": "Exodus",
"Lev": "Leviticus",
"Le": "Leviticus",
"Num": "Numbers",
"Nu": "Numbers",
"Deut": "Deuteronomy",
"Dt": "Deuteronomy",
"Josh": "Joshua",
"Jos": "Joshua",
"Judg": "Judges",
"Jdg": "Judges",
"Ru": "Ruth",
"1Sam": "1 Samuel",
"1 Sam": "1 Samuel",
"1S": "1 Samuel",
"2Sam": "2 Samuel",
"2 Sam": "2 Samuel",
"2S": "2 Samuel",
"1Ki": "1 Kings",
"1 Ki": "1 Kings",
"1K": "1 Kings",
"2Ki": "2 Kings",
"2 Ki": "2 Kings",
"2K": "2 Kings",
"1Chr": "1 Chronicles",
"1 Chr": "1 Chronicles",
"1Ch": "1 Chronicles",
"2Chr": "2 Chronicles",
"2 Chr": "2 Chronicles",
"2Ch": "2 Chronicles",
"Ezr": "Ezra",
"Neh": "Nehemiah",
"Ne": "Nehemiah",
"Est": "Esther",
"Ps": "Psalms",
"Psa": "Psalms",
"Prov": "Proverbs",
"Pr": "Proverbs",
"Eccl": "Ecclesiastes",
"Ec": "Ecclesiastes",
"Song": "Song of Solomon",
"Sos": "Song of Solomon",
"SS": "Song of Solomon",
"Isa": "Isaiah",
"Is": "Isaiah",
"Jer": "Jeremiah",
"Je": "Jeremiah",
"Lam": "Lamentations",
"La": "Lamentations",
"Ezek": "Ezekiel",
"Eze": "Ezekiel",
"Ezk": "Ezekiel",
"Dan": "Daniel",
"Da": "Daniel",
"Hos": "Hosea",
"Ho": "Hosea",
"Joe": "Joel",
"Jl": "Joel",
"Am": "Amos",
"Ob": "Obadiah",
"Jon": "Jonah",
"Mic": "Micah",
"Mi": "Micah",
"Nah": "Nahum",
"Na": "Nahum",
"Hab": "Habakkuk",
"Hb": "Habakkuk",
"Zep": "Zephaniah",
"Zph": "Zephaniah",
"Hag": "Haggai",
"Hg": "Haggai",
"Zech": "Zechariah",
"Zec": "Zechariah",
"Zch": "Zechariah",
"Mal": "Malachi",
# Common abbreviations - New Testament
"Mat": "Matthew",
"Mt": "Matthew",
"Mar": "Mark",
"Mk": "Mark",
"Mrk": "Mark",
"Luk": "Luke",
"Lk": "Luke",
"Joh": "John",
"Jn": "John",
"Act": "Acts",
"Ac": "Acts",
"Rom": "Romans",
"Ro": "Romans",
"1Cor": "1 Corinthians",
"1 Cor": "1 Corinthians",
"1Co": "1 Corinthians",
"2Cor": "2 Corinthians",
"2 Cor": "2 Corinthians",
"2Co": "2 Corinthians",
"Gal": "Galatians",
"Ga": "Galatians",
"Eph": "Ephesians",
"Ep": "Ephesians",
"Phil": "Philippians",
"Php": "Philippians",
"Ph": "Philippians",
"Col": "Colossians",
"Co": "Colossians",
"1Thess": "1 Thessalonians",
"1 Thess": "1 Thessalonians",
"1Th": "1 Thessalonians",
"2Thess": "2 Thessalonians",
"2 Thess": "2 Thessalonians",
"2Th": "2 Thessalonians",
"1Tim": "1 Timothy",
"1 Tim": "1 Timothy",
"1Ti": "1 Timothy",
"2Tim": "2 Timothy",
"2 Tim": "2 Timothy",
"2Ti": "2 Timothy",
"Tit": "Titus",
"Ti": "Titus",
"Phm": "Philemon",
"Pm": "Philemon",
"Heb": "Hebrews",
"He": "Hebrews",
"Jam": "James",
"Jas": "James",
"Jm": "James",
"1Pet": "1 Peter",
"1 Pet": "1 Peter",
"1Pe": "1 Peter",
"1P": "1 Peter",
"2Pet": "2 Peter",
"2 Pet": "2 Peter",
"2Pe": "2 Peter",
"2P": "2 Peter",
"1Joh": "1 John",
"1 Joh": "1 John",
"1Jn": "1 John",
"2Joh": "2 John",
"2 Joh": "2 John",
"2Jn": "2 John",
"3Joh": "3 John",
"3 Joh": "3 John",
"3Jn": "3 John",
"Jud": "Jude",
"Rev": "Revelation",
"Re": "Revelation",
}
def normalize_book_name(book: str) -> Optional[str]:
"""
Normalize book name variations to canonical form.
Returns the canonical book name if a variation is detected, None otherwise.
"""
return BOOK_ABBREVIATIONS.get(book)
def is_old_testament(book: str) -> bool:
"""Check if a book is in the Old Testament."""
return book in OT_BOOKS
def is_new_testament(book: str) -> bool:
"""Check if a book is in the New Testament."""
return book in NT_BOOKS
def get_testament(book: str) -> str:
"""Return the testament name for a book."""
if is_old_testament(book):
return "Old Testament"
elif is_new_testament(book):
return "New Testament"
return "Unknown"