Add KJV chapter shards and Strong's index

This commit is contained in:
2026-07-15 16:53:14 -05:00
parent 7759c0de6a
commit 60a65e0c14
2386 changed files with 394139 additions and 5 deletions
+69
View File
@@ -86,6 +86,10 @@ for (const entry of usfmEntries) {
}
await mkdir(outputDir, { recursive: true })
await rm(path.join(outputDir, 'verses-by-chapter'), { recursive: true, force: true })
await rm(path.join(outputDir, 'strongs-by-chapter'), { recursive: true, force: true })
await mkdir(path.join(outputDir, 'verses-by-chapter'), { recursive: true })
await mkdir(path.join(outputDir, 'strongs-by-chapter'), { recursive: true })
await writeFile(
path.join(outputDir, 'verses.jsonl'),
`${verses.map((verse) => JSON.stringify(verse)).join('\n')}\n`,
@@ -106,11 +110,21 @@ await writeFile(
`${studyNotes.map((note) => JSON.stringify(note)).join('\n')}\n`,
'utf8',
)
await writeFile(
path.join(outputDir, 'strongs-index.jsonl'),
`${buildStrongsIndex(strongsLinks).map((entry) => JSON.stringify(entry)).join('\n')}\n`,
'utf8',
)
await writeChapterPackages(outputDir, 'verses-by-chapter', verses)
await writeChapterPackages(outputDir, 'strongs-by-chapter', strongsLinks)
const versesPackage = await packageFile(outputDir, 'verses.jsonl')
const strongsPackage = await packageFile(outputDir, 'strongs-links.jsonl')
const strongsIndexPackage = await packageFile(outputDir, 'strongs-index.jsonl')
const footnotesPackage = await packageFile(outputDir, 'footnotes.jsonl')
const studyNotesPackage = await packageFile(outputDir, 'study-notes.jsonl')
const chapterVerseDir = await packageDirectory(outputDir, 'verses-by-chapter')
const chapterStrongDir = await packageDirectory(outputDir, 'strongs-by-chapter')
const catalog = {
schema_version: 'librebible.resource-catalog.v1',
@@ -145,8 +159,17 @@ const catalog = {
files: {
verses_jsonl: versesPackage,
strongs_jsonl: strongsPackage,
strongs_index_jsonl: strongsIndexPackage,
footnotes_jsonl: footnotesPackage,
study_notes_jsonl: studyNotesPackage,
chapter_verse_dir: {
...chapterVerseDir,
layout: '<BOOK>.<CHAPTER>.verses.jsonl',
},
chapter_strongs_dir: {
...chapterStrongDir,
layout: '<BOOK>.<CHAPTER>.strongs.jsonl',
},
},
}
@@ -220,6 +243,52 @@ async function packageFile(outputDir, fileName) {
}
}
async function packageDirectory(outputDir, dirName) {
return {
path: dirName,
}
}
async function writeChapterPackages(outputDir, dirName, entries) {
const groups = new Map()
for (const entry of entries) {
if (!entry.book_id || !entry.chapter) continue
const key = `${entry.book_id}.${entry.chapter}`
const current = groups.get(key) ?? []
current.push(entry)
groups.set(key, current)
}
for (const [key, group] of groups) {
const suffix = dirName === 'verses-by-chapter' ? 'verses' : 'strongs'
await writeFile(
path.join(outputDir, dirName, `${key}.${suffix}.jsonl`),
`${group.map((entry) => JSON.stringify(entry)).join('\n')}\n`,
'utf8',
)
}
}
function buildStrongsIndex(strongsLinks) {
const index = new Map()
for (const link of strongsLinks) {
const current = index.get(link.strong) ?? {
strong: link.strong,
verse_ids: [],
surfaces: [],
}
if (!current.verse_ids.includes(link.verse_id)) current.verse_ids.push(link.verse_id)
if (current.surfaces.length < 24 && link.surface && !current.surfaces.includes(link.surface)) {
current.surfaces.push(link.surface)
}
index.set(link.strong, current)
}
return [...index.values()].sort((left, right) => left.strong.localeCompare(right.strong))
}
function flushVerse(bookId, bookTitle, currentVerse) {
if (!bookId || !currentVerse) return