|
|
|
(define-module (bible-tools)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module (srfi srfi-98)
|
|
|
|
#:use-module (rnrs io ports)
|
|
|
|
#:use-module (rnrs bytevectors)
|
|
|
|
#:export (mapcan
|
|
|
|
get-bible
|
|
|
|
string->bible
|
|
|
|
clean-strings
|
|
|
|
book
|
|
|
|
chapter
|
|
|
|
verse
|
|
|
|
text
|
|
|
|
get-book
|
|
|
|
get-chapter
|
|
|
|
get-verse
|
|
|
|
let-bible
|
|
|
|
call-with-book
|
|
|
|
call-with-chapter
|
|
|
|
with-bible
|
|
|
|
with-book
|
|
|
|
with-chapter))
|
|
|
|
|
|
|
|
(define (mapcan f l) (apply append (map f l)))
|
|
|
|
(define make-bible-path
|
|
|
|
(cut string-append (get-environment-variable "HOME")
|
|
|
|
"/.bible/" <> ".tsv"))
|
|
|
|
(define (get-bible name)
|
|
|
|
(call-with-input-file (make-bible-path name)
|
|
|
|
(compose utf8->string get-bytevector-all)))
|
|
|
|
|
|
|
|
(define string->verse (cut string-split <> #\tab))
|
|
|
|
(define clean-strings
|
|
|
|
(cut filter (compose not (cut string=? <> "")) <>))
|
|
|
|
|
|
|
|
(define string->bible
|
|
|
|
(compose (cut map string->verse <>)
|
|
|
|
clean-strings
|
|
|
|
(cut string-split <> #\newline)))
|
|
|
|
|
|
|
|
(define book first)
|
|
|
|
(define chapter fourth)
|
|
|
|
(define verse fifth)
|
|
|
|
(define text sixth)
|
|
|
|
|
|
|
|
(define (get-num query bible part)
|
|
|
|
(filter (compose (cut = query <>) string->number part) bible))
|
|
|
|
(define (get-book book-name bible)
|
|
|
|
(filter (compose (cut string=? book-name <>) book) bible))
|
|
|
|
(define get-chapter (cut get-num <> <> chapter))
|
|
|
|
(define get-verse (cut get-num <> <> verse))
|
|
|
|
|
|
|
|
(define (with-bible b f)
|
|
|
|
(when (procedure? f) (f (string->bible (get-bible b)))))
|
|
|
|
|
|
|
|
(define (call-with-book book thunk)
|
|
|
|
(compose thunk (cut get-book book <>)))
|
|
|
|
(define (call-with-chapter book chapter thunk)
|
|
|
|
(lambda (bible) (thunk (get-chapter (string->number chapter)
|
|
|
|
(get-book book bible)))))
|