diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-23 12:49:21 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-23 12:49:21 +0200 |
| commit | 998e0d5bb2aa4412ca05d28f27592ae54727e2ba (patch) | |
| tree | e85f6fa309bd24347c21a1bf0ce555977f6cc4b0 /internal/bible/bible.go | |
| parent | 4273441011c9e29c2d7c387fc008d0b7b82f33d8 (diff) | |
| download | lectio-998e0d5bb2aa4412ca05d28f27592ae54727e2ba.tar.gz lectio-998e0d5bb2aa4412ca05d28f27592ae54727e2ba.zip | |
bible: embed corpora + chapter lookup
Diffstat (limited to 'internal/bible/bible.go')
| -rw-r--r-- | internal/bible/bible.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/bible/bible.go b/internal/bible/bible.go new file mode 100644 index 0000000..0254ceb --- /dev/null +++ b/internal/bible/bible.go @@ -0,0 +1,60 @@ +package bible + +import ( + "embed" + "strconv" + "strings" + "sync" +) + +//go:embed corpora/wuj.tsv corpora/vul.tsv corpora/grb.tsv corpora/drb.tsv +var corporaFS embed.FS + +// Verse is a single verse. +type Verse struct { + Chapter, Verse int + Text string +} + +type corpus struct { + books map[string]map[int][]Verse // book -> chapter -> verses (verse-ordered) +} + +var ( + corpora = map[string]*corpus{} + corporaMu sync.Mutex +) + +func load(version string) *corpus { + corporaMu.Lock() + defer corporaMu.Unlock() + if c, ok := corpora[version]; ok { + return c + } + data, err := corporaFS.ReadFile("corpora/" + version + ".tsv") + if err != nil { + corpora[version] = &corpus{books: map[string]map[int][]Verse{}} + return corpora[version] + } + c := &corpus{books: map[string]map[int][]Verse{}} + for _, line := range strings.Split(string(data), "\n") { + f := strings.Split(line, "\t") + if len(f) != 6 { + continue + } + chap, _ := strconv.Atoi(f[3]) + vn, _ := strconv.Atoi(f[4]) + book := f[0] + if c.books[book] == nil { + c.books[book] = map[int][]Verse{} + } + c.books[book][chap] = append(c.books[book][chap], Verse{chap, vn, f[5]}) + } + corpora[version] = c + return c +} + +// Verses returns all verses of one chapter of a book in a version (may be empty). +func Verses(version, book string, chap int) []Verse { + return load(version).books[book][chap] +} |
