sqlbible 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/bin/sqlbible +81 -6
- data/lib/sqlbible/convert.rb +2 -0
- data/lib/sqlbible/version.rb +6 -0
- data/lib/sqlbible.rb +51 -19
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db4b2a65f0c016b81b2d1ec4c0cb45c85bb619eacf7aa802cea2fcfda88048c
|
4
|
+
data.tar.gz: 61e97c6905189eec0a5cfc6ef1b02a8cc91dd1d4ecd1fe1d9250db1c9c93c423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba9e92407bc21109d36538b6932b04790a0d6082ca6131260280b6aaaf2b96e3bf42872d352637c8846ebb4d28999da222b0130a30ac41e47414d36684bd09a
|
7
|
+
data.tar.gz: c5250da5c011c5e4fb1e5f3536be717a84c550f9f10dd8c03d2665cdb369982aaa4fbab4d83a183010245621dda4cf092f05746f05f61c4349507dd96d1a4b5d
|
data/README.md
CHANGED
@@ -35,11 +35,14 @@ bible.reference(ref)
|
|
35
35
|
|
36
36
|
### Sqlbible as command-line application
|
37
37
|
|
38
|
+
It is possible to convert bibles in OSIS XML format to SQLite databases for
|
39
|
+
Sqlbible, to search for regular expressions and show text for references.
|
40
|
+
|
38
41
|
See help of the command-line application:
|
39
42
|
|
40
43
|
```shell
|
41
44
|
sqlbible -h
|
42
|
-
|
45
|
+
```
|
43
46
|
|
44
47
|
## Requirements
|
45
48
|
|
data/bin/sqlbible
CHANGED
@@ -2,18 +2,93 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
# frozen_string_literal: false
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'optimist_xl'
|
6
|
+
require 'scripref'
|
7
|
+
require 'sqlbible'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
result = OptimistXL.options do
|
10
|
+
synopsis 'Usage: sqlitebible [options] [<command> [suboptions] <filename>]'
|
11
|
+
subcmd :convert, 'Convert a bible from OSIS-XML to Sqlbible format' do
|
12
|
+
opt :output, 'Output filename of the generated Sqlbible file', type: String
|
13
|
+
end
|
14
|
+
subcmd :search, 'Search with regular expressions' do
|
15
|
+
opt :search, 'Regular expression to search (multiple allowed)', type: String, multi: true, required: true
|
16
|
+
opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
|
17
|
+
opt :output, 'Output filename', type: String
|
18
|
+
opt :range, 'Search range, example: "John 1-10"', type: String
|
19
|
+
end
|
20
|
+
subcmd :text, 'Show text of references' do
|
21
|
+
opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
|
22
|
+
opt :output, 'Output filename', type: String
|
23
|
+
opt :reference, 'Reference to show, example: "John 3:16; 10:27-30"', type: String, required: true
|
24
|
+
end
|
25
|
+
version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
|
26
|
+
end
|
27
|
+
|
28
|
+
unless filename = result.leftovers.first
|
29
|
+
$stderr.puts 'no filename given'
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def determine_lang_mod subopts
|
34
|
+
case l = subopts[:lang]
|
35
|
+
when 'en', nil
|
36
|
+
Scripref::English
|
37
|
+
when 'de'
|
38
|
+
Scripref::German
|
39
|
+
else
|
40
|
+
fail format("lang option #{l} is not supported")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def determine_out subopts
|
45
|
+
if fn = subopts[:output]
|
46
|
+
out = File.open(opts[:output], 'w')
|
47
|
+
else
|
48
|
+
out = $stdout
|
49
|
+
end
|
9
50
|
end
|
10
51
|
|
11
|
-
|
52
|
+
def format_verse f, v
|
53
|
+
format('%s: %s', f.format(v.scripref_passage), v.plaintext)
|
54
|
+
end
|
55
|
+
|
56
|
+
subopts = result.subcommand_options
|
57
|
+
|
58
|
+
case result.subcommand
|
59
|
+
when 'convert'
|
12
60
|
require 'sqlbible/convert'
|
13
|
-
|
61
|
+
osis_fn = filename
|
62
|
+
sqlite_fn = subopts[:output] || osis_fn.sub(/\.xml/i, '') << '.sqlite'
|
14
63
|
if $stdout.tty?
|
15
64
|
puts "convert #{osis_fn} to #{sqlite_fn} ..."
|
16
65
|
end
|
17
66
|
Sqlbible.convert osis_fn, sqlite_fn
|
67
|
+
exit
|
68
|
+
when 'search'
|
69
|
+
searches = subopts[:search]
|
70
|
+
lang_mod = determine_lang_mod(subopts)
|
71
|
+
if r = subopts[:range]
|
72
|
+
p = Scripref::Parser.new(lang_mod)
|
73
|
+
range = p.parse(r)
|
74
|
+
else
|
75
|
+
range = nil
|
76
|
+
end
|
77
|
+
out = determine_out subopts
|
78
|
+
bible = Sqlbible.new(filename)
|
79
|
+
regexes = searches.map {|s| Regexp.new(s)}
|
80
|
+
f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
|
81
|
+
bible.search(regexes, range: range).each do |v|
|
82
|
+
out.puts format_verse(f, v)
|
83
|
+
end
|
84
|
+
when 'text'
|
85
|
+
lang_mod = determine_lang_mod(subopts)
|
86
|
+
p = Scripref::Parser.new(lang_mod)
|
87
|
+
f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
|
88
|
+
ref = p.parse(subopts[:reference])
|
89
|
+
bible = Sqlbible.new(filename)
|
90
|
+
out = determine_out subopts
|
91
|
+
bible.reference(ref).flatten.each do |v|
|
92
|
+
out.puts format_verse(f, v)
|
93
|
+
end
|
18
94
|
end
|
19
|
-
|
data/lib/sqlbible/convert.rb
CHANGED
data/lib/sqlbible.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'scripref'
|
5
5
|
require 'sqlite3'
|
6
6
|
|
7
|
-
|
7
|
+
require_relative 'sqlbible/version'
|
8
8
|
|
9
|
-
|
9
|
+
class Sqlbible
|
10
10
|
|
11
11
|
def initialize db_filename
|
12
12
|
@db = SQLite3::Database.new(db_filename)
|
@@ -16,17 +16,22 @@ class Sqlbible
|
|
16
16
|
check_schema_version
|
17
17
|
end
|
18
18
|
|
19
|
+
# Get an array of Verse instances for a Scripref::Passage
|
19
20
|
def passage pass
|
20
21
|
rowid1, rowid2 = passage2rowids(pass)
|
21
22
|
res = select_text(where: 'rowid between ? and ?', args: [rowid1, rowid2])
|
22
23
|
parse_verse_list(res)
|
23
24
|
end
|
24
25
|
|
26
|
+
# Get an array of arrays of Verse instances for a Scripref reference (array
|
27
|
+
# of Scripref::Passage instances)
|
25
28
|
def reference ref
|
26
29
|
ref.select {|e| e.kind_of?(Scripref::Passage)}.map {|pass| passage(pass)}
|
27
30
|
end
|
28
31
|
|
29
|
-
|
32
|
+
# Get an array of Verse instances for a search with one ore more regular
|
33
|
+
# expressions (optional a search range of a Scripref reference is possible)
|
34
|
+
def search *searches, range: nil
|
30
35
|
where_arr = []
|
31
36
|
args = []
|
32
37
|
if range
|
@@ -35,17 +40,26 @@ class Sqlbible
|
|
35
40
|
where_arr == [or_join_where(where_arr)]
|
36
41
|
args = passages.map {|p| passage2rowids(p)}.flatten
|
37
42
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
searches.flatten.each do |o|
|
44
|
+
case o
|
45
|
+
when Regexp
|
46
|
+
where_arr << 'plaintext regexp ?'
|
47
|
+
args << o.to_s
|
48
|
+
else
|
49
|
+
fail format('search objects of class %s are not (yet) supported', o.class)
|
50
|
+
end
|
45
51
|
end
|
52
|
+
where = and_join_where(where_arr)
|
53
|
+
res = select_text(where: where, args: args)
|
46
54
|
parse_verse_list(res)
|
47
55
|
end
|
48
56
|
|
57
|
+
# Get the schema version of the SQLite database of the instance
|
58
|
+
def schema_version
|
59
|
+
Sqlbible.select_schema_version(@db)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Representation of a verse
|
49
63
|
Verse = Struct.new :osisid, :bookid, :chapter, :verse, :xml, :plaintext, keyword_init: true do
|
50
64
|
def scripref_passage
|
51
65
|
Scripref::Passage.new(b1: bookid, c1: chapter, v1: verse, b2: bookid, c2: chapter, v2: verse)
|
@@ -54,23 +68,41 @@ class Sqlbible
|
|
54
68
|
|
55
69
|
class << self
|
56
70
|
|
71
|
+
# Get the database schema as string
|
57
72
|
def db_schema
|
58
73
|
File.read(File.join(__dir__, '../schema.sql'))
|
59
74
|
end
|
60
75
|
|
61
|
-
|
76
|
+
# Get an array of the major and minor version of the database schema of the
|
77
|
+
# actual version of the lib
|
78
|
+
def schema_major_minor
|
79
|
+
lib_db = SQLite3::Database.new(':memory:')
|
80
|
+
lib_db.execute_batch(Sqlbible.db_schema)
|
81
|
+
select_schema_major_minor(lib_db)
|
82
|
+
end
|
62
83
|
|
63
|
-
|
84
|
+
# Get the version of the database schema of the actual version of the lib
|
85
|
+
def schema_version
|
86
|
+
schema_major_minor.join('.')
|
87
|
+
end
|
88
|
+
|
89
|
+
# Get an array of the major and minor version of an Sqlbible database
|
90
|
+
def select_schema_major_minor db
|
91
|
+
db.execute("select major, minor from schema_version").first
|
92
|
+
end
|
93
|
+
|
94
|
+
# Get the version of an Sqlbible database
|
95
|
+
def select_schema_version db
|
96
|
+
select_schema_major_minor(db).join('.')
|
97
|
+
end
|
64
98
|
|
65
|
-
def select_schema_version db
|
66
|
-
db.execute("select major, minor from schema_version").first
|
67
99
|
end
|
68
100
|
|
101
|
+
private
|
102
|
+
|
69
103
|
def check_schema_version
|
70
|
-
|
71
|
-
|
72
|
-
major_lib, minor_lib = select_schema_version(lib_db)
|
73
|
-
major_bible, minor_bible = select_schema_version(@db)
|
104
|
+
major_lib, minor_lib = Sqlbible.schema_major_minor
|
105
|
+
major_bible, minor_bible = Sqlbible.select_schema_major_minor(@db)
|
74
106
|
if major_bible < major_lib || major_bible == major_lib && minor_bible < minor_lib
|
75
107
|
fail 'database schema of bible database is too old'
|
76
108
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlbible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Friedrich
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2024-
|
10
|
+
date: 2024-11-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: nokogiri
|
@@ -24,19 +24,19 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '1.16'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: optimist_xl
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '3.
|
32
|
+
version: '3.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '3.
|
39
|
+
version: '3.3'
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: scripref
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- bin/sqlbible
|
91
91
|
- lib/sqlbible.rb
|
92
92
|
- lib/sqlbible/convert.rb
|
93
|
+
- lib/sqlbible/version.rb
|
93
94
|
- schema.sql
|
94
95
|
homepage: https://bitbucket.org/janfri/sqlbible
|
95
96
|
licenses:
|