Example

What is love?

Using emacs

Ephesians 4
From whom the whole body fitly joined together and compacted by that which every joint supplieth, according to the effectual working in the measure of every part, maketh increase of the body unto the edifying of itself in love.

Inserting a scripture into this document:

emacs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(defun search-bible-verse (query)
  (interactive (list (read-string-hist "Bible sem-search: ")))

  (let* ((result (fz (pen-sn (cmd
                             ;; "upd"
                              "oci" "semantic-bible-search" query))
                     nil nil "Bible: search result: "))
         (text (pen-sn "jq -r .text" result))
         (text (pen-sn "pen-str join ' '" text))
         (book (pen-sn "jq -r .book" result))
         (chapter (pen-sn "jq -r .chapter" result))
         (url (pen-sn "jq -r .url" result)))

    (xc (concat "+ [[" (chomp url) "][" (concat (chomp book) " " (chomp chapter)) "]] :: " text))))

CLI script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
export TTY
# shopt -s nullglob # use for 'for' loops but not for 'ls', 'grep'

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
    "") { shift; }; ;;
    -oc) {
        org_link=y
        shift
        shift
    }
    ;;

    *) break;
esac; done

tf_bible="/tmp/biblesearch.txt"

query="$@"

test -n "$query" || query="$(rlwrap readln "Bible search")"

test -n "$query" || exit 1

cd $HOME/source/git/hoffa/bible-search

CMD="$(cmd python bible_search.py "$query") | chomp > $tf_bible"

oci unbuffer x -cd "$HOME/source/git/hoffa/bible-search" -sh bash -s ". .venv/bin/activate; $CMD" -c m -e '$' -c d -i &>/dev/null

test -s "$tf_bible" || exit 1

if test "$org_link" = "y"; then
    sel="$(cat "$tf_bible" | mfz -nv)"

    test -n "$sel" || exit 1

    text="$(p "$sel" | jq -r .text | pen-str join ' ')"
    book="$(p "$sel" | jq -r .book)"
    chapter="$(p "$sel" | jq -r .chapter)"
    url="$(p "$sel" | jq -r .url)"
    link="+ [[$url][$book $chapter]] :: $text"
    printf -- "%s\n" "$link" | pavs
else
    cat "$tf_bible" | pavs
fi

bible_search.py

I made a modification of the streamlit app.py to run instead on the CLI.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import urllib

import sys

# Only use for st.cache
import streamlit as st

import json


from search import (
    search,
    get_model,
    read_books_df,
    read_text_df,
    read_embeddings_df,
    get_results_df,
)

query = "What is love?"

WEB_NAME = "World English Bible (WEB)"
KJV_NAME = "King James Version (KJV)"
YLT_NAME = "Young's Literal Translation (YLT)"
BBE_NAME = "Bible in Basic English (BBE)"

VERSIONS = {
    WEB_NAME: "web",
    KJV_NAME: "kjv",
    YLT_NAME: "ylt",
    BBE_NAME: "bbe",
}

version = "kjv"


@st.cache
def get_bible(version):
    books_df = read_books_df(
        f"https://github.com/hoffa/bible-search/releases/download/v1/{version}_books.parquet"
    )
    text_df = read_text_df(
        f"https://github.com/hoffa/bible-search/releases/download/v1/{version}_text.parquet"
    )
    embeddings_df, embeddings_tensor = read_embeddings_df(
        f"https://github.com/hoffa/bible-search/releases/download/v1/{version}_embeddings.parquet"
    )
    return books_df, text_df, embeddings_df, embeddings_tensor


@st.cache(allow_output_mutation=True)
def get_transformer():
    return get_model()


def get_verse_url(result, version):
    # BBE isn't on BibleGateway
    version = "niv" if version == "bbe" else version
    return "https://www.biblegateway.com/passage/?" + urllib.parse.urlencode(
        {
            "search": f"{result.book} {result.chapter}",
            "version": version,
        },
    )

def main():
    query = (len(sys.argv) > 1 and sys.argv[1])

    model = get_model()

    if query:
        model = get_transformer()
        books_df, text_df, embeddings_df, embeddings_tensor = get_bible(version)
        results_df = get_results_df(
            embeddings_df, model.encode(query), 50, embeddings_tensor
        )
        results = search(books_df, text_df, results_df)

        for result in results:
            # print(json.dumps(result))
            print("{ text: " + f"{json.dumps(result.text)}, book: {json.dumps(result.book)}, chapter: {result.chapter}, url: {json.dumps(get_verse_url(result, version))}" + "}")


if __name__ == "__main__":
    main()

More examples

Hebrews 9
The Holy Ghost this signifying, that the way into the holiest of all was not yet made manifest, while as the first tabernacle was yet standing: