bomdb 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7fbd83f638d94be3f15c4cf8442e2cdeccf8b1e
4
- data.tar.gz: 2625af19b7be4478cd1abf1a39900ff41d21e10c
3
+ metadata.gz: 6045b00d06ff5e4d4ae162ef54fe995df71ab90b
4
+ data.tar.gz: f252a2454c9a02f8db6e45ebcded298c1a52ef57
5
5
  SHA512:
6
- metadata.gz: 3c3d9acb48871cf5676c901c3d45b233a4d7e208da3d873b5b63930a2dbbe3d8456472b3045597f61493f8181b468f7d9a82defe4354d4252857ad2ded14ddcd
7
- data.tar.gz: 58c3914913e18e8aa645997b13599d33e4c5876ce9fbf0e0928fd17e8603baf20ef87dd50f20822922fc2761fe2e6db5907fe58f0d8350012ffff667c62d8e48
6
+ metadata.gz: 40de7880d7173f51e6505b5ca829ffdd056a81122b30561cd931f49f70c970800cbcbdf88fbd7835adc4ff90eabd50d43fb51020dc9a997ca2babf630b3cfa83
7
+ data.tar.gz: c9f8a9bcae9d097675516cea81320f18c22b3f605ab3401b1222675d15a600301ebeffc5eb5b41b28ed44621fbb23887d3654e6733550a630f990d40f8600eb6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bomdb (0.5.0)
4
+ bomdb (0.6.0)
5
5
  colorize (~> 0.7)
6
6
  constellation (~> 0.1)
7
7
  levenshtein-ffi (~> 1.1)
data/README.md CHANGED
@@ -8,7 +8,7 @@ BomDB is a command-line tool (packaged as a Ruby gem) that provides multiple edi
8
8
  Let's show the 1992 edition of the Book of Mormon:
9
9
 
10
10
  ```bash
11
- $ bomdb show 1992
11
+ $ bomdb show --edition=1992
12
12
 
13
13
  1 Nephi 1:1 I, Nephi, having been born of goodly parents, therefore I was taught somewhat in all the learning of my father...
14
14
  # ... etc ...
@@ -18,7 +18,7 @@ Moroni 10:34 And now I bid unto all, farewell. I soon go to rest in the paradis
18
18
  Or the 1829 printer's manuscript:
19
19
 
20
20
  ```bash
21
- $ bomdb show 1829
21
+ $ bomdb show --edition=1829
22
22
 
23
23
  1 Nephi 1:1 I Nephi having been born of goodly parents, therefore I was taught somewhat in all the learning of my father...
24
24
  # ... etc ...
@@ -27,7 +27,7 @@ Moroni 10:34 And now I bid unto all farewell. I soon go to rest in the paradise
27
27
  Suppose we want to remove the book, chapter, and verse headings from the output:
28
28
 
29
29
  ```bash
30
- $ bomdb show 1829 --no-verses
30
+ $ bomdb show --edition=1829 --no-verses
31
31
 
32
32
  I Nephi having been born of goodly parents, therefore I was taught somewhat in all the learning of my father...
33
33
  # ... etc ...
@@ -37,16 +37,32 @@ And now I bid unto all farewell. I soon go to rest in the paradise of God...
37
37
  Exclude verses in the Book of Mormon that are biblical inclusions:
38
38
 
39
39
  ```bash
40
- $ bomdb show 1829 --exclude Bible-OT
40
+ $ bomdb show --edition=1829 --exclude Bible-OT
41
41
  # ... shows 6080 verses instead of the usual 6604
42
42
  ```
43
43
 
44
+ Or, show only 1 Nephi, without Old Testament references:
45
+
46
+ ```bash
47
+ $ bomdb show '1 Nephi 1-22' --exclude Bible-OT
48
+ # ... shows 563 verses in 1st Nephi (1st Nephi has 618 verses,
49
+ # but some are from the Old Testament)
50
+ ```
51
+
52
+ BomDB uses the [Mericope](https://github.com/wordtreefoundation/mericope) gem to parse scriptural ranges ("pericopes"), so it is quite flexible:
53
+
54
+ ```bash
55
+ $ bomdb show 'Mosiah 5:1-2,6'
56
+ Mosiah 5:1 And now it came to pass that when king Benjamin had thus spoken...
57
+ Mosiah 5:2 And they all cried with one voice, saying: Yea, we believe...
58
+ Mosiah 5:6 And now these are the words which king Benjamin desired of them...
59
+ ```
44
60
 
45
61
  ### IMPORT and EXPORT portions of the database
46
62
 
47
63
  You can import and export any part of the database, such as the books, verses, editions, and contents (text) of the database.
48
64
 
49
- The github repository contains a set of "starter" json file that are used to seed the database with some reasonable structure and data; however, these json files are absent in the packaged Gem. If you've cloned the github repo, you can re-create the database from scratch:
65
+ The github repository contains a set of "starter" json files that are used to seed the database with some reasonable structure and data; however, these json files are absent in the packaged Gem. If you've cloned the github repo, you can use these files to re-create the database from scratch:
50
66
 
51
67
  ```bash
52
68
  $ bundle exec bin/bomdb create
@@ -141,13 +157,17 @@ Note that `align` requires the [dwdiff](http://linux.die.net/man/1/dwdiff) comma
141
157
 
142
158
  ### Custom Queries
143
159
 
144
- Here's a simple way to analyze the Book of Mormon to see the wherefore/therefore divergence leading to the [Mosiah Priority](http://signaturebookslibrary.org/new-approaches-to-the-book-of-mormon-10/) (Mosiah was written before 1 Nephi) hypothesis:
160
+ Here's a simple way to analyze the Book of Mormon to see the wherefore/therefore divergence leading to the [Mosiah Priority](http://signaturebookslibrary.org/new-approaches-to-the-book-of-mormon-10/) hypothesis (Mosiah was written before 1 Nephi):
145
161
 
146
162
  ```ruby
147
163
  $ bundle exec irb -rbomdb
148
164
  irb(main):001:0> q = BomDB::Query.new(exclude: 'Bible-OT')
149
165
  => #<BomDB::Query:0x007f90ad1cb408 @edition=1829, @exclude="Bible-OT", @headings=false>
150
- irb(main):002:0> q.books.map{ |book,content| [book, content.scan(/wherefore/i).size, content.scan(/therefore/i).size] }
166
+ irb(main):002:0> q.books.map do |book,content|
167
+ [book,
168
+ content.scan(/wherefore/i).size,
169
+ content.scan(/therefore/i).size]
170
+ end
151
171
  => [
152
172
  ["1 Nephi", 99, 13], ["2 Nephi", 126, 6], ["Jacob", 53, 1],
153
173
  ["Enos", 6, 0], ["Jarom", 3, 0], ["Omni", 6, 0], ["Words of Mormon", 5, 0],
@@ -187,12 +207,48 @@ end
187
207
  # Moroni WWWWWWWWWWWW
188
208
  ```
189
209
 
190
- Other possible enumerables on a Query include:
210
+ Other possible enumerables on a Query object include:
191
211
 
192
212
  - books: enumerate on each book of the Book of Mormon
193
213
  - chapters: enumerate on each book and chapter of the Book of Mormon
194
214
  - wordgroups(N): enumerate on consecutive N words, e.g. each 1000 words
195
215
 
216
+ ### Custom Queries and Charts
217
+
218
+ Let's zoom in on the interesting book, Ether, where the Wherefore/Therefore crossover occurs:
219
+
220
+ ```ruby
221
+ require 'bomdb'
222
+ require 'google_chart' # gem is called 'gchartrb'
223
+
224
+ q = BomDB::Query.new(range: 'Ether 1-15')
225
+
226
+ data = q.chapters.map do |(book, chapter), content|
227
+ words = content.scan(/ +/).size
228
+ wh = content.scan(/wherefore/i).size.to_f / words
229
+ th = content.scan(/therefore/i).size.to_f / words
230
+ [chapter, wh, th]
231
+ end
232
+
233
+ axis_labels = data.map(&:first)
234
+ wherefores = data.map{ |d| d[1] }
235
+ therefores = data.map{ |d| d[2] }
236
+ y_max = [wherefores.max, therefores.max].max
237
+ title = 'Wherefores/Therefores Per Word in Ether'
238
+
239
+ GoogleChart::LineChart.new('600x400', title, false) do |chart|
240
+ chart.data "Wherefores", wherefores, '2200ff'
241
+ chart.show_legend = true
242
+ chart.data "Therefores", therefores, 'ff2200'
243
+ chart.axis :y, range: [0.0, y_max], font_size: 16
244
+ chart.axis :x, range: axis_labels, font_size: 16
245
+ chart.grid x_step: 20.0, y_step: 30.0, length_segment: 1, length_blank: 0
246
+ puts chart.to_url
247
+ end
248
+ ```
249
+
250
+ ![Wherefore/Therefores in Ether](http://chart.apis.google.com/chart?chs=600x400&cht=lc&chco=2200ff,ff2200&chxt=y,x&chxr=0,0.0,0.009721322099805573|1,1,15&chg=20.0,30.0,1.0,0.0&chd=s:AJOOcFpeRaQ8eWX,UJiVcRGFNAAEAAE&chdl=Wherefores|Therefores&chtt=Wherefores/Therefores+Per+Word+in+Ether+by+Chapter)
251
+
196
252
  ## Installation
197
253
 
198
254
  Ruby 2.1 is required. You should also have a normal build environment set up, e.g. command line tools on the mac, or GCC on Linux.
@@ -201,6 +257,8 @@ To install BomDB for use on the command line, use `gem install`:
201
257
 
202
258
  $ gem install bomdb
203
259
 
260
+ To install `dwdiff` on your Mac OS X system: `brew install dwdiff`, or on Ubuntu: `sudo apt-get install dwdiff`.
261
+
204
262
  To include bomdb in another Ruby app, add this line to your application's `Gemfile`:
205
263
 
206
264
  ```ruby
@@ -10,9 +10,12 @@ module BomDB
10
10
 
11
11
 
12
12
  desc "import FILE", "import data from FILE into database, e.g. books.json"
13
- option :type, :type => :string, :default => nil
14
- option :format, :type => :string, :default => 'json'
15
- option :edition, :type => :string, :default => nil
13
+ option :type, :type => :string, :default => nil,
14
+ :description => "type of data to import, i.e. one of: books, verses, editions, contents, refs"
15
+ option :format, :type => :string, :default => 'json',
16
+ :description => "format of the data being imported. One of: json, text"
17
+ option :edition, :type => :string, :default => nil,
18
+ :description => "edition of the Book of Mormon in which to import (assumes type=contents) (required when format=text)"
16
19
  def import(file)
17
20
  type = (options[:type] || type_from_file(file)).downcase
18
21
  format = (options[:format] || format_from_file(file)).downcase
@@ -40,9 +43,11 @@ module BomDB
40
43
 
41
44
 
42
45
 
43
- desc "export TYPE", "export data from the database, e.g. books"
44
- option :format, :type => :string, :default => 'json'
45
- option :editions, :type => :string, :default => :all
46
+ desc "export TYPE", "export data from the database, i.e. one of: books, verses, editions, contents"
47
+ option :format, :type => :string, :default => 'json',
48
+ :description => "format of the data being imported. One of: json, text"
49
+ option :editions, :type => :string, :default => :all,
50
+ :description => "edition(s) of the Book of Mormon to export. Defaults to 'all' editions."
46
51
  def export(type)
47
52
  format = options[:format].downcase
48
53
 
@@ -116,11 +121,13 @@ module BomDB
116
121
 
117
122
 
118
123
 
119
- desc "show EDITION RANGE", "show an edition of the Book of Mormon, or a RANGE of verses"
124
+ desc "show RANGE", "show a RANGE of verses in the Book of Mormon (defaults to 1829 edition)"
120
125
  option :verses, :type => :boolean, :default => true,
121
126
  :description => "show book, chapter, verse annotations"
122
127
  option :exclude, :type => :string, :aliases => [:x],
123
128
  :description => "exclude verses that are references, e.g. Bible-OT references"
129
+ option :"exclude-only-quotations", :type => :boolean, :aliases => [:q],
130
+ :description => "don't exclude verses with references that are non-quotations"
124
131
  option :sep, :type => :string, :default => " ",
125
132
  :description => "separator between annotations and content, defaults to ' '"
126
133
  option :linesep, :type => :string, :default => "\n",
@@ -131,7 +138,11 @@ module BomDB
131
138
  :description => "show output in 'alignment' mode. Useful for debugging 'align' subcommand issues."
132
139
  option :clean, :type => :boolean, :default => false,
133
140
  :description => "remove punctuation and normalize text by sentence"
134
- def show(edition = '1992', range = nil)
141
+ option :edition, :type => :string, :default => '1829',
142
+ :description => "show verses from a specific edition (see 'editions' command for list)"
143
+ option :search, :type => :string, :default => nil,
144
+ :description => "show only verses that contain the search term"
145
+ def show(range = nil)
135
146
  body_format = nil
136
147
  wordsep = options[:sep]
137
148
  linesep = options[:linesep]
@@ -161,9 +172,11 @@ module BomDB
161
172
  end
162
173
  end
163
174
  BomDB::Query.new(
164
- edition: edition,
165
- exclude: options[:exclude]
166
- # range: range
175
+ edition: options[:edition],
176
+ range: range,
177
+ search: options[:search],
178
+ exclude: options[:exclude],
179
+ exclude_only_quotations: options[:"exclude-only-quotations"]
167
180
  ).print(
168
181
  verse_format: verse_format,
169
182
  body_format: body_format,
@@ -222,8 +235,16 @@ module BomDB
222
235
  map { |r| "#{r[:ref_name]} (#{r[:count]} refs)" }
223
236
  puts rts.join("\n")
224
237
  else
225
- rts = BomDB.db[:refs].where(:ref_name => type).
226
- map{ |r| "#{r[:ref_book]} #{r[:ref_chapter]}:#{r[:ref_verse]}" }
238
+ rts = BomDB.db[:refs].
239
+ where(:ref_name => type).
240
+ join(:verses, :verse_id => :verse_id).
241
+ join(:books, :book_id => :book_id).
242
+ map do |r|
243
+ asterisk = r[:ref_is_quotation] ? '*' : ''
244
+ "#{r[:ref_book]} #{r[:ref_chapter]}:#{r[:ref_verse]} => " +
245
+ "#{r[:book_name]} #{r[:verse_chapter]}:#{r[:verse_number]}" +
246
+ "#{asterisk}"
247
+ end
227
248
  puts rts.join("\n")
228
249
  end
229
250
  end
@@ -2,9 +2,12 @@ require 'bomdb/models/edition'
2
2
 
3
3
  module BomDB
4
4
  class Query
5
- def initialize(edition: 1829, exclude: nil, headings: false)
5
+ def initialize(edition: 1829, range: nil, search: nil, exclude: nil, exclude_only_quotations: false, headings: false)
6
6
  @edition = edition
7
+ @range = range
8
+ @search = search
7
9
  @exclude = exclude
10
+ @exclude_only_quotations = exclude_only_quotations
8
11
  @headings = headings
9
12
  end
10
13
 
@@ -23,9 +26,20 @@ module BomDB
23
26
  select(:book_name, :verse_chapter, :verse_number, :content_body)
24
27
  q.where!(:editions__edition_id => edition[:edition_id]) if @edition
25
28
  q.where!(:verse_heading => nil) unless @headings
29
+ if @range
30
+ pericope = Mericope.new(@range)
31
+ pairs = pericope.ranges.map{ |r| [:verse_range_id, r] }
32
+ q.where!(Sequel::SQL::BooleanExpression.from_value_pairs(pairs, :OR))
33
+ end
34
+ if @search
35
+ q.where!(Sequel.like(Sequel.function(:LOWER, :content_body), "%#{@search.downcase}%"))
36
+ end
26
37
  if @exclude
27
38
  excluded_verse_ids = db[:refs].select(:verse_id).
28
39
  where(:ref_name => @exclude.split(/\s*,\s*/))
40
+ if @exclude_only_quotations
41
+ excluded_verse_ids.where!(ref_is_quotation: true)
42
+ end
29
43
  q.exclude!(:verses__verse_id => excluded_verse_ids)
30
44
  end
31
45
  q
@@ -83,12 +97,16 @@ module BomDB
83
97
  io.print sep
84
98
  end
85
99
  begin
86
- io.print body_format[ row[:content_body] ]
100
+ content_body = row[:content_body]
101
+ if @search
102
+ content_body.gsub!(@search, @search.red)
103
+ end
104
+ io.print body_format[ content_body ]
87
105
  rescue TypeError
88
106
  next
89
107
  end
90
108
  end
91
- io.puts "Nothing shown" unless shown
109
+ io.puts "Nothing to show" unless shown
92
110
  end
93
111
  end
94
112
  end
@@ -1,3 +1,3 @@
1
1
  module BomDB
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bomdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duane Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel