Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Darby and Chinese Union versions #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
kjv: kjv.sh kjv.awk kjv.tsv
cat kjv.sh > $@

echo 'exit 0' >> $@

echo '#EOF' >> $@
tar cz kjv.awk kjv.tsv >> $@
chmod +x $@

darby: darby.sh kjv.awk darby.tsv
cat darby.sh > $@
echo 'exit 0' >> $@
echo '#EOF' >> $@
tar cz kjv.awk darby.tsv >> $@
chmod +x $@

chiuns: chiuns.sh kjv.awk chiuns.tsv
cat chiuns.sh > $@
echo 'exit 0' >> $@
echo '#EOF' >> $@
tar cz kjv.awk chiuns.tsv >> $@
chmod +x $@

test: kjv.sh
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,36 @@ kjv can be built by cloning the repository and then running make:

git clone https://github.com/bontibon/kjv.git
cd kjv
make

To make different versions:
make kjv
make darby
make chiuns

- To make the naming easier, can rename these binaries, such as: mv chiuns cus
These binaries can be put at a place on the path for usage (such as ~/.local/bin/ etc. )

## License

Public domain

## Develop

Here are the notes for further develop this commandline tool.
Format of the kjv.tsv - it's tab seperated bible verses, one line per verse:
- column 1: Book title: Genesis
- column 2: Abbreviated book title: Ge
- column 3: Book number: For genesis, it's 1
- column 4: chapter number
- column 5: verse number

Convert other Bible versions to this tsv format:

- One way is to use diatheke (included in sword project), use the first 4 columns, to query the verse in the other version, to build a tsv Bible file.
: diatheke -b Darby -o M -k John 3:1
: This command return 2 lines: line 1:
the verse together with the John 3:16 as index
This line of returned text, truncate the first several chars which is the index for the verse: we can use the same length + 1 to remove the verse index.

the second line is the (Darby) version: this second line can be omitted when reformatting for the Darby (or other different version of the Bible).

95 changes: 95 additions & 0 deletions chiuns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh
# chiuns: Read the Word of God from your terminal
# License: Public domain

SELF="$0"

get_data() {
sed '1,/^#EOF$/d' < "$SELF" | tar xz -O "$1"
}

if [ -z "$PAGER" ]; then
if command -v less >/dev/null; then
PAGER="less"
else
PAGER="cat"
fi
fi

show_help() {
exec >&2
echo "usage: $(basename "$0") [flags] [reference...]"
echo
echo " -l list books"
echo " -W no line wrap"
echo " -h show help"
echo
echo " Reference types:"
echo " <Book>"
echo " Individual book"
echo " <Book>:<Chapter>"
echo " Individual chapter of a book"
echo " <Book>:<Chapter>:<Verse>[,<Verse>]..."
echo " Individual verse(s) of a specific chapter of a book"
echo " <Book>:<Chapter>-<Chapter>"
echo " Range of chapters in a book"
echo " <Book>:<Chapter>:<Verse>-<Verse>"
echo " Range of verses in a book chapter"
echo " <Book>:<Chapter>:<Verse>-<Chapter>:<Verse>"
echo " Range of chapters and verses in a book"
echo
echo " /<Search>"
echo " All verses that match a pattern"
echo " <Book>/<Search>"
echo " All verses in a book that match a pattern"
echo " <Book>:<Chapter>/<Search>"
echo " All verses in a chapter of a book that match a pattern"
exit 2
}

while [ $# -gt 0 ]; do
isFlag=0
firstChar="${1%"${1#?}"}"
if [ "$firstChar" = "-" ]; then
isFlag=1
fi

if [ "$1" = "--" ]; then
shift
break
elif [ "$1" = "-l" ]; then
# List all book names with their abbreviations
get_data chiuns.tsv | awk -v cmd=list "$(get_data kjv.awk)"
exit
elif [ "$1" = "-W" ]; then
export chiuns_NOLINEWRAP=1
shift
elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
show_help
else
break
fi
done

cols=$(tput cols 2>/dev/null)
if [ $? -eq 0 ]; then
export chiuns_MAX_WIDTH="$cols"
fi

if [ $# -eq 0 ]; then
if [ ! -t 0 ]; then
show_help
fi

# Interactive mode
while true; do
printf "chiuns> "
if ! read -r ref; then
break
fi
get_data chiuns.tsv | awk -v cmd=ref -v ref="$ref" "$(get_data kjv.awk)" | ${PAGER}
done
exit 0
fi

get_data chiuns.tsv | awk -v cmd=ref -v ref="$*" "$(get_data kjv.awk)" | ${PAGER}
31,102 changes: 31,102 additions & 0 deletions chiuns.tsv

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions convert_chiuns.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use diatheke command line to obtain Darby version

rm(list=ls())
library(data.table)

# Loading the kjv.tsv data
d = fread("kjv.tsv")

get_darby = function(verse_index) {
# Function to get darby version by diatheke
# Input is the verse_index: 1 John 3:1
# Output is the Darby version to be included
command = paste0("diatheke -b ChiUns -f plain -k ", verse_index)
verse = system(command, intern=TRUE)
return_verse = substring(verse[1], nchar(verse_index) + 3)
# print(paste("-- converting:", verse_index)) ## just for debugging, may slow down converting process
return(return_verse)
}

d$index = paste0(d$V1, " ", d$V4, ":", d$V5)
# d = d[1:10, ]
d$verse =sapply(d$index, get_darby)

# Save the converted version
d1 = d[, .(V1, V2, V3, V4, V5, verse)]
fwrite(d1, 'chiuns.tsv', col.names=F, sep="\t")
28 changes: 28 additions & 0 deletions convert_darby.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use diatheke command line to obtain Darby version

rm(list=ls())
library(data.table)

# Loading the kjv.tsv data
d = fread("kjv.tsv")

get_darby = function(verse_index) {
# Function to get darby version by diatheke
# Input is the verse_index: 1 John 3:1
# Output is the Darby version to be included
command = paste0("diatheke -b Darby -f plain -k ", verse_index)
verse = system(command, intern=TRUE)
return_verse = substring(verse[1], nchar(verse_index) + 3)
# print(paste("-- converting:", verse_index)) ## just for debugging, may slow down converting process
return(return_verse)
}

d$index = paste0(d$V1, " ", d$V4, ":", d$V5)
# d = d[1:10, ]
d$verse =sapply(d$index, get_darby)


# Save the converted version
d1 = d[, .(V1, V2, V3, V4, V5, verse)]
fwrite(d1, 'darby.tsv', col.names=F, sep="\t")

95 changes: 95 additions & 0 deletions darby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh
# darby: Read the Word of God from your terminal
# License: Public domain

SELF="$0"

get_data() {
sed '1,/^#EOF$/d' < "$SELF" | tar xz -O "$1"
}

if [ -z "$PAGER" ]; then
if command -v less >/dev/null; then
PAGER="less"
else
PAGER="cat"
fi
fi

show_help() {
exec >&2
echo "usage: $(basename "$0") [flags] [reference...]"
echo
echo " -l list books"
echo " -W no line wrap"
echo " -h show help"
echo
echo " Reference types:"
echo " <Book>"
echo " Individual book"
echo " <Book>:<Chapter>"
echo " Individual chapter of a book"
echo " <Book>:<Chapter>:<Verse>[,<Verse>]..."
echo " Individual verse(s) of a specific chapter of a book"
echo " <Book>:<Chapter>-<Chapter>"
echo " Range of chapters in a book"
echo " <Book>:<Chapter>:<Verse>-<Verse>"
echo " Range of verses in a book chapter"
echo " <Book>:<Chapter>:<Verse>-<Chapter>:<Verse>"
echo " Range of chapters and verses in a book"
echo
echo " /<Search>"
echo " All verses that match a pattern"
echo " <Book>/<Search>"
echo " All verses in a book that match a pattern"
echo " <Book>:<Chapter>/<Search>"
echo " All verses in a chapter of a book that match a pattern"
exit 2
}

while [ $# -gt 0 ]; do
isFlag=0
firstChar="${1%"${1#?}"}"
if [ "$firstChar" = "-" ]; then
isFlag=1
fi

if [ "$1" = "--" ]; then
shift
break
elif [ "$1" = "-l" ]; then
# List all book names with their abbreviations
get_data darby.tsv | awk -v cmd=list "$(get_data kjv.awk)"
exit
elif [ "$1" = "-W" ]; then
export darby_NOLINEWRAP=1
shift
elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
show_help
else
break
fi
done

cols=$(tput cols 2>/dev/null)
if [ $? -eq 0 ]; then
export darby_MAX_WIDTH="$cols"
fi

if [ $# -eq 0 ]; then
if [ ! -t 0 ]; then
show_help
fi

# Interactive mode
while true; do
printf "darby> "
if ! read -r ref; then
break
fi
get_data darby.tsv | awk -v cmd=ref -v ref="$ref" "$(get_data kjv.awk)" | ${PAGER}
done
exit 0
fi

get_data darby.tsv | awk -v cmd=ref -v ref="$*" "$(get_data kjv.awk)" | ${PAGER}
Loading