bibletools 0.2.0 → 0.2.2

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
  SHA256:
3
- metadata.gz: c6ae238a57f75318c4238835d64567683523fdcf106e3a4eba8007e833de88ac
4
- data.tar.gz: bd3471c321d7caf26d360bc66ee44eda5b3276d808de12e4ec450044a5f62515
3
+ metadata.gz: e10c0e0f8c335ebc195c2086d59c3d27a9a4f3d2c19e42ba85bca938365a4c2b
4
+ data.tar.gz: bf5259405950f58998288d7d17f783a6672600c053617e56e34a5363c44f938f
5
5
  SHA512:
6
- metadata.gz: 5dddc1de4ef4dc2439a3f3ca8d4e49a7973dd89c06362ac1761be02ed2240a09367b622b3abdac5ad919f23c49ef3e72ee63dbac13bd4818aa3abe57b19dddb7
7
- data.tar.gz: b39d63a2795fc9468e176ee44e674a79042e2f5608c64099b9604ce8e8d75f75376cd26fd6040760f5c113579fba00cfb1c8ee5d1c345576c1a064d54d9443a4
6
+ metadata.gz: f8e7b6f0a5246ab59b5db9732c8ea29e34e354c687f6a6bdae7971a99f89947a53252acad367d0a006984fbd1bf7c8349f09cf21b2b7f9b4e66d42a25a53e087
7
+ data.tar.gz: 9fd82593908e3f1a97b0a65f5d7b77bc34b8fc3e343abe1d4b81e66d4f8bb152dab81efcf3a0424a306d8df4621c7bff5a93473e5cf3b9a4e70ae8950ed897b8
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/bibletools.rb CHANGED
@@ -93,17 +93,21 @@ module BibleTools
93
93
 
94
94
  class Scraper
95
95
 
96
- def initialize(book: 'Exodus', url: '')
96
+ def initialize(book: 'Exodus', url: '', debug: false)
97
97
 
98
98
  raise ScraperErr, 'Please specify the URL' if url.empty?
99
99
 
100
100
  baseurl = url
101
101
 
102
102
  id = if book.is_a? String then
103
- (BOOKS.index(book) + 1).to_s
103
+ i = BOOKS.index(book.gsub(/\b./){|x| x.upcase})
104
+ puts 'book *' + book + '* not found' unless i
105
+ (i + 1).to_s
104
106
  else
105
107
  book.to_s
106
108
  end
109
+
110
+ puts 'id: ' + id.inspect if @debug
107
111
 
108
112
  url2 = baseurl + '?id=' + id
109
113
  doc = Nokorexi.new(url2).to_doc
@@ -163,8 +167,8 @@ module BibleTools
163
167
  @debug = debug
164
168
 
165
169
  if bible_obj then
170
+
166
171
  @doc = bible_obj.to_doc
167
- @verses = @doc.root.xpath('chapter/verse')
168
172
  @check = EnglishSpellcheck.new debug: false #verbose: false
169
173
 
170
174
  if tts then
@@ -180,9 +184,28 @@ module BibleTools
180
184
  # Automatically select verses; verses are selected based upon word
181
185
  # frequency
182
186
  #
183
- def asr()
187
+ def asr(chapters: [])
188
+
189
+ r = if chapters.any? then
190
+
191
+ doc = Rexle.new('<book/>')
192
+
193
+ chapters.each do |n|
194
+ e2 = @doc.root.element("chapter[@no='#{n.to_s}']")
195
+ doc.root.add e2 if e2
196
+ end
197
+
198
+ return doc
199
+
200
+ keyword = wordtally(doc: doc).keys.first
201
+ #return keyword
202
+ #get the wordstally for the chapters
203
+ assoc_r(keyword, doc)
204
+
205
+ else
206
+ assoc_r()
207
+ end
184
208
 
185
- r = assoc_r()
186
209
  e = r[1].root.element('chapter/verse')
187
210
  verse_no = e.attributes[:no]
188
211
  chptr_no = e.parent.attributes[:no]
@@ -190,16 +213,18 @@ module BibleTools
190
213
  # we are backtracking the results to hopefully find a new branch to explore
191
214
  trail = r.first
192
215
 
216
+ #return r
193
217
  a, trail2 = mine_words(r, trail, level: 2)
194
218
  a << [chptr_no, verse_no, e.text, 1]
195
-
219
+ puts 'a: ' + a.inspect
220
+ #return a
196
221
  h = a.group_by(&:first)
197
222
  a2 = h.sort_by {|x, _| x.to_i}
198
- a3 = a2.map do |chapter, verses|
223
+ @verses = a2.map do |chapter, verses|
199
224
  [chapter, verses.sort_by {|_,x| x.to_i}]
200
225
  end
201
226
 
202
- [a3, trail2]
227
+ [@verses, trail2]
203
228
  end
204
229
 
205
230
  # find the words associated with a given keyword
@@ -266,9 +291,12 @@ module BibleTools
266
291
  def search(keyword, doc=@doc)
267
292
 
268
293
  verses = doc.root.xpath('chapter/verse')
294
+ puts 'verses: ' + verses.inspect
269
295
  a = verses.select {|x| x.text =~ /#{keyword}/i}
270
296
 
271
297
  a2 = a.map.with_index do |verse, i|
298
+
299
+ #puts 'verse: ' + verse.xml.inspect
272
300
  txt = verse.text
273
301
 
274
302
  puts 'txt: ' + txt.inspect if @debug
@@ -278,9 +306,11 @@ module BibleTools
278
306
 
279
307
  until txt.rstrip[/[\.\?!]\W*$/] or n > 2 do
280
308
  n +=1
309
+ puts 'n: ' + n.inspect
281
310
  nverse = read(chapter, verse.attributes[:no].to_i + n)[0]
311
+ puts 'nverse: ' + nverse.inspect
282
312
  puts 'nverse: ' + nverse&.text.inspect if @debug
283
- txt += nverse.text
313
+ txt += nverse.text if nverse
284
314
  end
285
315
 
286
316
  if @debug then
@@ -321,6 +351,52 @@ module BibleTools
321
351
 
322
352
  end
323
353
 
354
+ def verses(level: nil, html: false, title: nil)
355
+
356
+ a = @verses.map {|_, body| body}.flatten(1)
357
+ a1 = level ? a.select {|c,v,t,l| l <= level} : a.map {|c,v,t,l| [c,v,t]}
358
+ a2 = a1.map {|c,v,t,l| [c,v,t]}.uniq
359
+ h = a2.group_by(&:first)
360
+
361
+ puts 'html: ' + html.inspect
362
+ return h unless html == true
363
+
364
+ doc = Rexle.new('<html/>')
365
+
366
+
367
+ head = Rexle::Element.new('head')
368
+ head.add(Rexle::Element.new('h1').add_text(title) ) if title
369
+
370
+ style = Rexle::Element.new('style')
371
+ style.add_text ' ins {font-size: 0.8em;padding: 0.8em;}'
372
+ head.add style
373
+
374
+ doc.root.add head
375
+ body = Rexle::Element.new('body')
376
+
377
+ h.each do |chptr, verses|
378
+
379
+ h2 = Rexle::Element.new('h2').add_text chptr
380
+ body.add h2
381
+
382
+ verses.each do |cno, vno, text|
383
+
384
+ ins = Rexle::Element.new('ins').add_text vno
385
+ para = Rexle::Element.new('p')
386
+ para.add ins
387
+ para.add_text text
388
+ body.add para
389
+
390
+ end
391
+
392
+ end
393
+
394
+ doc.root.add body
395
+
396
+ doc.root.xml pretty: true
397
+
398
+ end
399
+
324
400
  private
325
401
 
326
402
  def mine_words(r, trail, verses=[], level: 0)
@@ -329,28 +405,32 @@ module BibleTools
329
405
  found = []
330
406
  (i-=1; found = r.last[i][0].keys - trail) until found.any?
331
407
  r2 = r.last[i][0].keys - trail
408
+
332
409
  a3 = r2.map do |x|
410
+
333
411
  _, doc_verse = assoc_r x, r.last[i][1]
334
412
  chaptr_no = doc_verse.root.element('chapter').attributes[:no]
335
413
  everse = doc_verse.root.element('chapter/verse')
336
414
  verse_no = everse.attributes[:no]
415
+
337
416
  [chaptr_no, verse_no, everse.text, level]
417
+
338
418
  end.uniq
339
419
 
340
- #a3b = a3.group_by {|x| x[0]}.map(&:last).flatten(1).sort_by {|x| x[0].to_i}
341
- #a3b.length
342
-
343
420
  puts 'verses: ' + verses.inspect if @debug
421
+
344
422
  verses.concat a3
345
423
  verses.uniq!
346
424
  trail.concat r2
425
+
347
426
  puts 'trail.length: ' + trail.length.inspect if @debug
348
427
  puts 'verses.length: ' + verses.length.inspect if @debug
349
428
 
350
- if verses.length < 30 or trail.length < 100
351
- mine_words(r, trail, verses, level: level+1)
352
- else
429
+ if verses.length > 30 or trail.length > 100
353
430
  [verses, trail]
431
+ else
432
+
433
+ mine_words(r, trail, verses, level: level+1)
354
434
  end
355
435
  end
356
436
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibletools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -36,7 +36,7 @@ cert_chain:
36
36
  hIlyeyH9vsaJLam1TYsSqh3KUBmRCIvc3XELg2MAlggTrHuCjBPdYXqjIOFvO6HZ
37
37
  Z1XDnMf4RhcEPF4AU3Q+Fefsw4qKRWH3YUw=
38
38
  -----END CERTIFICATE-----
39
- date: 2022-11-05 00:00:00.000000000 Z
39
+ date: 2023-01-19 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokorexi
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.3.7
147
+ rubygems_version: 3.4.4
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Performs a word count within a specified book. Returns the verses within
metadata.gz.sig CHANGED
Binary file