codexparser 0.0.58 → 0.0.59

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.
@@ -1,9 +1,14 @@
1
1
  const bcv_parser = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
2
- const text = "Revelation 3:5; 7:14; 12:7; 13:8; 16:18; 20:1-6"
2
+ const util = require("util")
3
+
4
+ const dump = (item) => {
5
+ console.log(util.inspect(item, { depth: null, colors: true }))
6
+ }
7
+ const text = "Genesis 1:1 John 1:1"
3
8
 
4
9
  const parser = new bcv_parser()
5
10
  const textParser = parser.parse(text)
6
11
  const passages = textParser.parsed_entities()
7
12
  passages.forEach((passage) => {
8
- console.log(passage)
13
+ dump(passage)
9
14
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "This is a Javascript Bible parser and text scanner. It will search through texts and collate all scripture references into an array and parse them into objects, and it will parse passages into objects by book, chapter, verse, and testament. ",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/scan-test.js ADDED
@@ -0,0 +1,11 @@
1
+ const BibleParser = require("./src/CodexParser.js")
2
+ const util = require("util")
3
+
4
+ const dump = (item) => {
5
+ console.log(util.inspect(item, { depth: null, colors: true }))
6
+ }
7
+ const string = "Genesis 1:1 John 1:1"
8
+ console.log(string)
9
+ const parser = new BibleParser()
10
+ const result = parser.find(string)
11
+ dump(result)
@@ -204,6 +204,313 @@ class CodexParser {
204
204
  .replace(/\s+:\s+/g, ":")
205
205
  .trim()
206
206
  }
207
+ find(text) {
208
+ const books = [
209
+ "Gen",
210
+ "Ge",
211
+ "Gn",
212
+ "Exo",
213
+ "Ex",
214
+ "Exod",
215
+ "Lev",
216
+ "Le",
217
+ "Lv",
218
+ "Num",
219
+ "Nu",
220
+ "Nm",
221
+ "Nb",
222
+ "Deut",
223
+ "Dt",
224
+ "Josh",
225
+ "Jos",
226
+ "Jsh",
227
+ "Judg",
228
+ "Jdg",
229
+ "Jg",
230
+ "Jdgs",
231
+ "Rth",
232
+ "Ru",
233
+ "Sam",
234
+ "Samuel",
235
+ "Kings",
236
+ "Kgs",
237
+ "Kin",
238
+ "Chron",
239
+ "Chronicles",
240
+ "Ezra",
241
+ "Ezr",
242
+ "Ez",
243
+ "Neh",
244
+ "Ne",
245
+ "Esth",
246
+ "Es",
247
+ "Job",
248
+ "Job",
249
+ "Jb",
250
+ "Pslm",
251
+ "Ps",
252
+ "Psalms",
253
+ "Psa",
254
+ "Psm",
255
+ "Pss",
256
+ "Prov",
257
+ "Pr",
258
+ "Prv",
259
+ "Eccles",
260
+ "Ec",
261
+ "Song",
262
+ "So",
263
+ "Canticles",
264
+ "Song of Songs",
265
+ "SOS",
266
+ "Isa",
267
+ "Is",
268
+ "Jer",
269
+ "Je",
270
+ "Jr",
271
+ "Lam",
272
+ "La",
273
+ "Ezek",
274
+ "Eze",
275
+ "Ezk",
276
+ "Dan",
277
+ "Da",
278
+ "Dn",
279
+ "Hos",
280
+ "Ho",
281
+ "Joel",
282
+ "Joe",
283
+ "Jl",
284
+ "Amos",
285
+ "Am",
286
+ "Obad",
287
+ "Ob",
288
+ "Jnh",
289
+ "Jon",
290
+ "Micah",
291
+ "Mic",
292
+ "Nah",
293
+ "Na",
294
+ "Hab",
295
+ "Zeph",
296
+ "Zep",
297
+ "Zp",
298
+ "Haggai",
299
+ "Hag",
300
+ "Hg",
301
+ "Zech",
302
+ "Zec",
303
+ "Zc",
304
+ "Mal",
305
+ "Mal",
306
+ "Ml",
307
+ "Matt",
308
+ "Mt",
309
+ "Mrk",
310
+ "Mk",
311
+ "Mr",
312
+ "Luk",
313
+ "Lk",
314
+ "John",
315
+ "Jn",
316
+ "Jhn",
317
+ "Acts",
318
+ "Ac",
319
+ "Rom",
320
+ "Ro",
321
+ "Rm",
322
+ "Co",
323
+ "Cor",
324
+ "Corinthians",
325
+ "Gal",
326
+ "Ga",
327
+ "Ephes",
328
+ "Eph",
329
+ "Phil",
330
+ "Php",
331
+ "Col",
332
+ "Col",
333
+ "Th",
334
+ "Thes",
335
+ "Thess",
336
+ "Thessalonians",
337
+ "Ti",
338
+ "Tim",
339
+ "Timothy",
340
+ "Titus",
341
+ "Tit",
342
+ "Philem",
343
+ "Phm",
344
+ "Hebrews",
345
+ "Heb",
346
+ "He",
347
+ "James",
348
+ "Jas",
349
+ "Jm",
350
+ "Pe",
351
+ "Pet",
352
+ "Pt",
353
+ "Peter",
354
+ "Jn",
355
+ "Jo",
356
+ "Joh",
357
+ "Jhn",
358
+ "John",
359
+ "Jude",
360
+ "Jd",
361
+ "Jud",
362
+ "Jud",
363
+ "Rev",
364
+ "The Revelation",
365
+ "Genesis",
366
+ "Exodus",
367
+ "Leviticus",
368
+ "Numbers",
369
+ "Deuteronomy",
370
+ "Joshua",
371
+ "Judges",
372
+ "Ruth",
373
+ "Samuel",
374
+ "Kings",
375
+ "Chronicles",
376
+ "Ezra",
377
+ "Nehemiah",
378
+ "Esther",
379
+ "Job",
380
+ "Psalms",
381
+ "Psalm",
382
+ "Proverbs",
383
+ "Ecclesiastes",
384
+ "Song of Solomon",
385
+ "Isaiah",
386
+ "Jeremiah",
387
+ "Lamentations",
388
+ "Ezekiel",
389
+ "Daniel",
390
+ "Hosea",
391
+ "Joel",
392
+ "Amos",
393
+ "Obadiah",
394
+ "Jonah",
395
+ "Micah",
396
+ "Nahum",
397
+ "Habakkuk",
398
+ "Zephaniah",
399
+ "Haggai",
400
+ "Zechariah",
401
+ "Malachi",
402
+ "Matthew",
403
+ "Mark",
404
+ "Luke",
405
+ "John",
406
+ "Acts",
407
+ "Romans",
408
+ "Corinthians",
409
+ "Galatians",
410
+ "Ephesians",
411
+ "Philippians",
412
+ "Colossians",
413
+ "Thessalonians",
414
+ "Timothy",
415
+ "Titus",
416
+ "Philemon",
417
+ "Hebrews",
418
+ "James",
419
+ "Peter",
420
+ "John",
421
+ "Revelation",
422
+ "Re",
423
+ "Ap",
424
+ "Jd.",
425
+ "Heb.",
426
+ ]
427
+
428
+ const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
429
+ const preStringed = [
430
+ "Sam",
431
+ "Samuel",
432
+ "Kings",
433
+ "Kgs",
434
+ "Kin",
435
+ "Chron",
436
+ "Chronicles",
437
+ "Corinthians",
438
+ "Co",
439
+ "Cor",
440
+ "Thessalonians",
441
+ "Th",
442
+ "Thes",
443
+ "Thess",
444
+ "Timothy",
445
+ "Ti",
446
+ "Tim",
447
+ "Peter",
448
+ "Pe",
449
+ "Pet",
450
+ "Pt",
451
+ "John",
452
+ "Jn",
453
+ "Jhn",
454
+ ]
455
+
456
+ //add the prestringed versions e.g. 1 Peter
457
+ for (let b = 0; b < preStringed.length; b++) {
458
+ for (let pre = 0; pre < preStrings.length; pre++) {
459
+ books.push(preStrings[pre] + " " + preStringed[b])
460
+ }
461
+ }
462
+ // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
463
+ const length = books.length
464
+ for (let b = 0; b < length; b++) {
465
+ books.push(books[b] + ".")
466
+ }
467
+
468
+ // sort descending - longer items first
469
+ books.sort((a, b) => b.length - a.length)
470
+ let booksAt = []
471
+ // go thro' each book finding where it matches in text
472
+ for (let b = 0; b < books.length; b++) {
473
+ const book = books[b]
474
+ let chNoInText = 0
475
+ while (chNoInText < text.length) {
476
+ let j = text.indexOf(book, chNoInText)
477
+ if (j < 0) break
478
+ if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
479
+ booksAt.push([book, j])
480
+ let replacement = book
481
+ for (let k = 0; k < book.length; k++) {
482
+ replacement = replacement.replace(book.charAt(k), "X")
483
+ }
484
+ text = text.replace(book, replacement) // to prevent a shorter version matching
485
+ }
486
+ chNoInText = j + book.length + 1
487
+ }
488
+ }
489
+ // into ascending order of start position
490
+ booksAt.sort(function (a, b) {
491
+ return a[1] - b[1]
492
+ })
493
+ let newText = ""
494
+ let chNoInText = 0
495
+ for (let b = 0; b < booksAt.length; b++) {
496
+ while (chNoInText < booksAt[b][1]) {
497
+ //copy across characters to start of book
498
+ newText += text.charAt(chNoInText)
499
+ chNoInText++
500
+ }
501
+ newText += booksAt[b][0]
502
+ chNoInText += booksAt[b][0].length //skip the 'fill-in characters
503
+ for (let i = 0; i < 100; i++) {
504
+ chNoInText++
505
+ const nextCh = text.charAt(chNoInText)
506
+ //test whether are at the end of the chapter(s) and verse(s)
507
+ if (nextCh.match(/^[a-z]+$/)) break
508
+ if (nextCh.match(/^[A-Z]+$/)) break
509
+ newText += text.charAt(chNoInText - 1)
510
+ }
511
+ }
512
+ return newText
513
+ }
207
514
  }
208
515
 
209
516
  module.exports = CodexParser
@@ -4,7 +4,8 @@ const util = require("util")
4
4
  const dump = (item) => {
5
5
  console.log(util.inspect(item, { depth: null, colors: true }))
6
6
  }
7
- const string = "Gen 1 Jd1 Ps 119:2,4,6,8,19"
7
+ const string = "Genesis 1:1 John 1:1"
8
+ console.log(string)
8
9
  const parser = new BibleParser()
9
10
  const result = parser.parse(string)
10
11
  dump(result.getPassages())