codexparser 0.0.78 → 0.0.80
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.
- package/bcv-single-test.js +3 -1
- package/find-test.js +20 -0
- package/jstester.js +12 -3
- package/package.json +1 -1
- package/scan-test.js +2 -15
- package/src/CodexParser.js +321 -48
- package/src/abbr.js +0 -1
- package/sub-verse-scripture-test.js +2 -1
- package/tests/find.js +7 -0
package/bcv-single-test.js
CHANGED
|
@@ -4,13 +4,15 @@ const util = require("util")
|
|
|
4
4
|
const dump = (item) => {
|
|
5
5
|
console.log(util.inspect(item, { depth: null, colors: true }))
|
|
6
6
|
}
|
|
7
|
-
const text = "
|
|
7
|
+
const text = "Psalm 95:6 MT"
|
|
8
8
|
|
|
9
9
|
const parser = new bcv_parser({
|
|
10
10
|
invalid_sequence_strategy: "include",
|
|
11
11
|
invalid_passage_strategy: "include",
|
|
12
|
+
sequence_combination_strategy: "combine"
|
|
12
13
|
})
|
|
13
14
|
const textParser = parser.parse(text)
|
|
15
|
+
console.log(textParser)
|
|
14
16
|
const passages = textParser.parsed_entities()
|
|
15
17
|
passages.forEach((passage) => {
|
|
16
18
|
dump(passage)
|
package/find-test.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const BibleParser = require("./src/CodexParser.js")
|
|
2
|
+
|
|
3
|
+
let text = `Joel 10:13 The passages Luke 2:32 and Lk 1:23 that we are looking at tonight 1 Cor 12:34 2 Cor 3:4 are found Jude 6, in Jude 5, Genesis 2:1 - 3:19, 1 John 3:16-17, 1 Peter 1:1, and Romans 10:13, 15, 17. Please turn in your Bibles. Ps 109:4,5,6,8. Isaiah 61.2-3 Mt 5.4
|
|
4
|
+
|
|
5
|
+
Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
|
|
6
|
+
|
|
7
|
+
Jd. 5
|
|
8
|
+
Jd 6
|
|
9
|
+
|
|
10
|
+
1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
|
|
11
|
+
|
|
12
|
+
Leviticus 16:6 He 5.3 He 7.27
|
|
13
|
+
|
|
14
|
+
Hos 10:1-3, 8 and 1 John 2:23f
|
|
15
|
+
|
|
16
|
+
exod15.18. 2 Cor 12:23 Malachi 3:32`
|
|
17
|
+
|
|
18
|
+
const parser = new BibleParser()
|
|
19
|
+
const result = parser.find("Isaiah 29:16; 45:9 // Romans 9:20").enhance()
|
|
20
|
+
console.log(result)
|
package/jstester.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const BibleParser = require("./src/CodexParser.js")
|
|
2
|
+
const parser = new BibleParser()
|
|
1
3
|
const books = [
|
|
2
4
|
"Gen",
|
|
3
5
|
"Ge",
|
|
@@ -298,13 +300,16 @@ booksAt.sort(function (a, b) {
|
|
|
298
300
|
})
|
|
299
301
|
newText = ""
|
|
300
302
|
let chNoInText = 0
|
|
303
|
+
|
|
304
|
+
let passages = []
|
|
301
305
|
for (let b = 0; b < booksAt.length; b++) {
|
|
302
306
|
while (chNoInText < booksAt[b][1]) {
|
|
303
307
|
//copy across characters to start of book
|
|
304
308
|
newText += text.charAt(chNoInText)
|
|
305
309
|
chNoInText++
|
|
306
310
|
}
|
|
307
|
-
newText += booksAt[b][0]
|
|
311
|
+
newText += "<span class='passage'>" + booksAt[b][0]
|
|
312
|
+
let passage = booksAt[b][0]
|
|
308
313
|
chNoInText += booksAt[b][0].length //skip the 'fill-in characters
|
|
309
314
|
for (let i = 0; i < 100; i++) {
|
|
310
315
|
chNoInText++
|
|
@@ -313,8 +318,12 @@ for (let b = 0; b < booksAt.length; b++) {
|
|
|
313
318
|
if (nextCh.match(/^[a-z]+$/)) break
|
|
314
319
|
if (nextCh.match(/^[A-Z]+$/)) break
|
|
315
320
|
newText += text.charAt(chNoInText - 1)
|
|
321
|
+
passage += text.charAt(chNoInText - 1)
|
|
316
322
|
}
|
|
317
|
-
|
|
323
|
+
passages.push(passage.trim())
|
|
324
|
+
newText += "</span> "
|
|
318
325
|
}
|
|
319
326
|
|
|
320
|
-
|
|
327
|
+
const found = parser.find(text)
|
|
328
|
+
|
|
329
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.80",
|
|
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
CHANGED
|
@@ -4,20 +4,7 @@ const util = require("util")
|
|
|
4
4
|
const dump = (item) => {
|
|
5
5
|
console.log(util.inspect(item, { depth: null, colors: true }))
|
|
6
6
|
}
|
|
7
|
-
let text = `
|
|
8
|
-
|
|
9
|
-
Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
|
|
10
|
-
|
|
11
|
-
Jd. 5
|
|
12
|
-
Jd 6
|
|
13
|
-
|
|
14
|
-
1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
|
|
15
|
-
|
|
16
|
-
Leviticus 16:6 He 5.3 He 7.27
|
|
17
|
-
|
|
18
|
-
Hos 10:1-3, 8 and 1 John 2:23
|
|
19
|
-
|
|
20
|
-
exod15.18. 2 Cor 12:23 Malachi 3:32`
|
|
7
|
+
let text = `Psalm 94:4-100:6 MT`
|
|
21
8
|
const parser = new BibleParser()
|
|
22
|
-
const result = parser.find(text)
|
|
9
|
+
const result = parser.find(text).enhance()
|
|
23
10
|
dump(result)
|
package/src/CodexParser.js
CHANGED
|
@@ -90,6 +90,7 @@ class CodexParser {
|
|
|
90
90
|
}
|
|
91
91
|
this.passages = []
|
|
92
92
|
this.scan(reference)
|
|
93
|
+
const books = []
|
|
93
94
|
for (let i = 0; i < this.found.length; i++) {
|
|
94
95
|
const result = this.found[i]
|
|
95
96
|
if (result.type === "range" && result.start.b !== result.end.b) {
|
|
@@ -125,7 +126,8 @@ class CodexParser {
|
|
|
125
126
|
next = this.found[i + 1]
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
+
|
|
130
|
+
if (passage.type === "range" && result.start.b === result.end.b) {
|
|
129
131
|
if (result.start.c !== result.end.c) {
|
|
130
132
|
passage.verses = [result.start.v]
|
|
131
133
|
passage.to = {
|
|
@@ -228,65 +230,336 @@ class CodexParser {
|
|
|
228
230
|
return parts
|
|
229
231
|
.join(" ")
|
|
230
232
|
.replace(/\s+:\s+/g, ":")
|
|
233
|
+
.replace(/\s[-–—]\s/, "-")
|
|
231
234
|
.trim()
|
|
232
235
|
}
|
|
233
236
|
find(text) {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
const books = [
|
|
238
|
+
"Gen",
|
|
239
|
+
"Ge",
|
|
240
|
+
"Gn",
|
|
241
|
+
"Exo",
|
|
242
|
+
"Ex",
|
|
243
|
+
"Exod",
|
|
244
|
+
"Lev",
|
|
245
|
+
"Le",
|
|
246
|
+
"Lv",
|
|
247
|
+
"Num",
|
|
248
|
+
"Nu",
|
|
249
|
+
"Nm",
|
|
250
|
+
"Nb",
|
|
251
|
+
"Deut",
|
|
252
|
+
"Dt",
|
|
253
|
+
"Josh",
|
|
254
|
+
"Jos",
|
|
255
|
+
"Jsh",
|
|
256
|
+
"Judg",
|
|
257
|
+
"Jdg",
|
|
258
|
+
"Jg",
|
|
259
|
+
"Jdgs",
|
|
260
|
+
"Rth",
|
|
261
|
+
"Ru",
|
|
262
|
+
"Sam",
|
|
263
|
+
"Samuel",
|
|
264
|
+
"Kings",
|
|
265
|
+
"Kgs",
|
|
266
|
+
"Kin",
|
|
267
|
+
"Chron",
|
|
268
|
+
"Chronicles",
|
|
269
|
+
"Ezra",
|
|
270
|
+
"Ezr",
|
|
271
|
+
"Ez",
|
|
272
|
+
"Neh",
|
|
273
|
+
"Ne",
|
|
274
|
+
"Esth",
|
|
275
|
+
"Es",
|
|
276
|
+
"Job",
|
|
277
|
+
"Job",
|
|
278
|
+
"Jb",
|
|
279
|
+
"Pslm",
|
|
280
|
+
"Ps",
|
|
281
|
+
"Psalms",
|
|
282
|
+
"Psa",
|
|
283
|
+
"Psm",
|
|
284
|
+
"Pss",
|
|
285
|
+
"Prov",
|
|
286
|
+
"Pr",
|
|
287
|
+
"Prv",
|
|
288
|
+
"Eccles",
|
|
289
|
+
"Ec",
|
|
290
|
+
"Song",
|
|
291
|
+
"So",
|
|
292
|
+
"Canticles",
|
|
293
|
+
"Song of Songs",
|
|
294
|
+
"SOS",
|
|
295
|
+
"Isa",
|
|
296
|
+
"Is",
|
|
297
|
+
"Jer",
|
|
298
|
+
"Je",
|
|
299
|
+
"Jr",
|
|
300
|
+
"Lam",
|
|
301
|
+
"La",
|
|
302
|
+
"Ezek",
|
|
303
|
+
"Eze",
|
|
304
|
+
"Ezk",
|
|
305
|
+
"Dan",
|
|
306
|
+
"Da",
|
|
307
|
+
"Dn",
|
|
308
|
+
"Hos",
|
|
309
|
+
"Ho",
|
|
310
|
+
"Joel",
|
|
311
|
+
"Joe",
|
|
312
|
+
"Jl",
|
|
313
|
+
"Amos",
|
|
314
|
+
"Am",
|
|
315
|
+
"Obad",
|
|
316
|
+
"Ob",
|
|
317
|
+
"Jnh",
|
|
318
|
+
"Jon",
|
|
319
|
+
"Micah",
|
|
320
|
+
"Mic",
|
|
321
|
+
"Nah",
|
|
322
|
+
"Na",
|
|
323
|
+
"Hab",
|
|
324
|
+
"Zeph",
|
|
325
|
+
"Zep",
|
|
326
|
+
"Zp",
|
|
327
|
+
"Haggai",
|
|
328
|
+
"Hag",
|
|
329
|
+
"Hg",
|
|
330
|
+
"Zech",
|
|
331
|
+
"Zec",
|
|
332
|
+
"Zc",
|
|
333
|
+
"Mal",
|
|
334
|
+
"Mal",
|
|
335
|
+
"Ml",
|
|
336
|
+
"Matt",
|
|
337
|
+
"Mt",
|
|
338
|
+
"Mrk",
|
|
339
|
+
"Mk",
|
|
340
|
+
"Mr",
|
|
341
|
+
"Luk",
|
|
342
|
+
"Lk",
|
|
343
|
+
"John",
|
|
344
|
+
"Jn",
|
|
345
|
+
"Jhn",
|
|
346
|
+
"Acts",
|
|
347
|
+
"Ac",
|
|
348
|
+
"Rom",
|
|
349
|
+
"Ro",
|
|
350
|
+
"Rm",
|
|
351
|
+
"Co",
|
|
352
|
+
"Cor",
|
|
353
|
+
"Corinthians",
|
|
354
|
+
"Gal",
|
|
355
|
+
"Ga",
|
|
356
|
+
"Ephes",
|
|
357
|
+
"Eph",
|
|
358
|
+
"Phil",
|
|
359
|
+
"Php",
|
|
360
|
+
"Col",
|
|
361
|
+
"Col",
|
|
362
|
+
"Th",
|
|
363
|
+
"Thes",
|
|
364
|
+
"Thess",
|
|
365
|
+
"Thessalonians",
|
|
366
|
+
"Ti",
|
|
367
|
+
"Tim",
|
|
368
|
+
"Timothy",
|
|
369
|
+
"Titus",
|
|
370
|
+
"Tit",
|
|
371
|
+
"Philem",
|
|
372
|
+
"Phm",
|
|
373
|
+
"Hebrews",
|
|
374
|
+
"Heb",
|
|
375
|
+
"He",
|
|
376
|
+
"James",
|
|
377
|
+
"Jas",
|
|
378
|
+
"Jm",
|
|
379
|
+
"Pe",
|
|
380
|
+
"Pet",
|
|
381
|
+
"Pt",
|
|
382
|
+
"Peter",
|
|
383
|
+
"Jn",
|
|
384
|
+
"Jo",
|
|
385
|
+
"Joh",
|
|
386
|
+
"Jhn",
|
|
387
|
+
"John",
|
|
388
|
+
"Jude",
|
|
389
|
+
"Jd",
|
|
390
|
+
"Jud",
|
|
391
|
+
"Jud",
|
|
392
|
+
"Rev",
|
|
393
|
+
"The Revelation",
|
|
394
|
+
"Genesis",
|
|
395
|
+
"Exodus",
|
|
396
|
+
"Leviticus",
|
|
397
|
+
"Numbers",
|
|
398
|
+
"Deuteronomy",
|
|
399
|
+
"Joshua",
|
|
400
|
+
"Judges",
|
|
401
|
+
"Ruth",
|
|
402
|
+
"Samuel",
|
|
403
|
+
"Kings",
|
|
404
|
+
"Chronicles",
|
|
405
|
+
"Ezra",
|
|
406
|
+
"Nehemiah",
|
|
407
|
+
"Esther",
|
|
408
|
+
"Job",
|
|
409
|
+
"Psalms",
|
|
410
|
+
"Psalm",
|
|
411
|
+
"Proverbs",
|
|
412
|
+
"Ecclesiastes",
|
|
413
|
+
"Song of Solomon",
|
|
414
|
+
"Isaiah",
|
|
415
|
+
"Jeremiah",
|
|
416
|
+
"Lamentations",
|
|
417
|
+
"Ezekiel",
|
|
418
|
+
"Daniel",
|
|
419
|
+
"Hosea",
|
|
420
|
+
"Joel",
|
|
421
|
+
"Amos",
|
|
422
|
+
"Obadiah",
|
|
423
|
+
"Jonah",
|
|
424
|
+
"Micah",
|
|
425
|
+
"Nahum",
|
|
426
|
+
"Habakkuk",
|
|
427
|
+
"Zephaniah",
|
|
428
|
+
"Haggai",
|
|
429
|
+
"Zechariah",
|
|
430
|
+
"Malachi",
|
|
431
|
+
"Matthew",
|
|
432
|
+
"Mark",
|
|
433
|
+
"Luke",
|
|
434
|
+
"John",
|
|
435
|
+
"Acts",
|
|
436
|
+
"Romans",
|
|
437
|
+
"Corinthians",
|
|
438
|
+
"Galatians",
|
|
439
|
+
"Ephesians",
|
|
440
|
+
"Philippians",
|
|
441
|
+
"Colossians",
|
|
442
|
+
"Thessalonians",
|
|
443
|
+
"Timothy",
|
|
444
|
+
"Titus",
|
|
445
|
+
"Philemon",
|
|
446
|
+
"Hebrews",
|
|
447
|
+
"James",
|
|
448
|
+
"Peter",
|
|
449
|
+
"John",
|
|
450
|
+
"Revelation",
|
|
451
|
+
"Re",
|
|
452
|
+
"Ap",
|
|
453
|
+
"Jd.",
|
|
454
|
+
"Heb.",
|
|
455
|
+
]
|
|
243
456
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
457
|
+
const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
|
|
458
|
+
const preStringed = [
|
|
459
|
+
"Sam",
|
|
460
|
+
"Samuel",
|
|
461
|
+
"Kings",
|
|
462
|
+
"Kgs",
|
|
463
|
+
"Kin",
|
|
464
|
+
"Chron",
|
|
465
|
+
"Chronicles",
|
|
466
|
+
"Corinthians",
|
|
467
|
+
"Co",
|
|
468
|
+
"Cor",
|
|
469
|
+
"Thessalonians",
|
|
470
|
+
"Th",
|
|
471
|
+
"Thes",
|
|
472
|
+
"Thess",
|
|
473
|
+
"Timothy",
|
|
474
|
+
"Ti",
|
|
475
|
+
"Tim",
|
|
476
|
+
"Peter",
|
|
477
|
+
"Pe",
|
|
478
|
+
"Pet",
|
|
479
|
+
"Pt",
|
|
480
|
+
"John",
|
|
481
|
+
"Jn",
|
|
482
|
+
"Jhn",
|
|
483
|
+
]
|
|
484
|
+
let newText = ""
|
|
264
485
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
486
|
+
//add the prestringed versions e.g. 1 Peter
|
|
487
|
+
for (let b = 0; b < preStringed.length; b++) {
|
|
488
|
+
for (let pre = 0; pre < preStrings.length; pre++) {
|
|
489
|
+
books.push(preStrings[pre] + " " + preStringed[b])
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
|
|
493
|
+
const length = books.length
|
|
494
|
+
for (let b = 0; b < length; b++) {
|
|
495
|
+
books.push(books[b] + ".")
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// sort descending - longer items first
|
|
499
|
+
books.sort((a, b) => b.length - a.length)
|
|
500
|
+
let booksAt = []
|
|
501
|
+
// go thro' each book finding where it matches in text
|
|
502
|
+
for (let b = 0; b < books.length; b++) {
|
|
503
|
+
const book = books[b]
|
|
504
|
+
let chNoInText = 0
|
|
505
|
+
while (chNoInText < text.length) {
|
|
506
|
+
let j = text.indexOf(book, chNoInText)
|
|
507
|
+
if (j < 0) break
|
|
508
|
+
if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
|
|
509
|
+
booksAt.push([book, j])
|
|
510
|
+
let replacement = book
|
|
511
|
+
for (let k = 0; k < book.length; k++) {
|
|
512
|
+
replacement = replacement.replace(book.charAt(k), "X")
|
|
275
513
|
}
|
|
276
|
-
|
|
514
|
+
text = text.replace(book, replacement) // to prevent a shorter version matching
|
|
277
515
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
516
|
+
chNoInText = j + book.length + 1
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// into ascending order of start position
|
|
520
|
+
booksAt.sort(function (a, b) {
|
|
521
|
+
return a[1] - b[1]
|
|
522
|
+
})
|
|
523
|
+
newText = ""
|
|
524
|
+
let chNoInText = 0
|
|
525
|
+
for (let b = 0; b < booksAt.length; b++) {
|
|
526
|
+
while (chNoInText < booksAt[b][1]) {
|
|
527
|
+
//copy across characters to start of book
|
|
528
|
+
newText += text.charAt(chNoInText)
|
|
529
|
+
chNoInText++
|
|
530
|
+
}
|
|
531
|
+
newText += "<span class='passage'>" + booksAt[b][0]
|
|
532
|
+
let passage = booksAt[b][0]
|
|
533
|
+
chNoInText += booksAt[b][0].length //skip the 'fill-in characters
|
|
534
|
+
for (let i = 0; i < 100; i++) {
|
|
535
|
+
chNoInText++
|
|
536
|
+
const nextCh = text.charAt(chNoInText)
|
|
537
|
+
//test whether are at the end of the chapter(s) and verse(s)
|
|
538
|
+
if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff") break
|
|
539
|
+
if (nextCh.match(/^[A-Z]+$/)) break
|
|
540
|
+
newText += text.charAt(chNoInText - 1)
|
|
541
|
+
passage += text.charAt(chNoInText - 1)
|
|
542
|
+
}
|
|
543
|
+
this.found.push(passage.trim())
|
|
544
|
+
newText += "</span> "
|
|
545
|
+
}
|
|
546
|
+
console.log(newText)
|
|
547
|
+
return this
|
|
548
|
+
}
|
|
282
549
|
|
|
283
|
-
|
|
284
|
-
|
|
550
|
+
enhance() {
|
|
551
|
+
if (this.found.length > 0) {
|
|
552
|
+
for (let i = 0; i < this.found.length; i++) {
|
|
553
|
+
const passage = {
|
|
554
|
+
original: this.found[i],
|
|
555
|
+
book: this.bookify(this.found[i].match(this.bookRegex)[0]),
|
|
556
|
+
chapter: this.found[i].match(this.chapterRegex),
|
|
557
|
+
verse: this.found[i].match(this.verseRegex)[0],
|
|
285
558
|
}
|
|
286
559
|
this.passages.push(passage)
|
|
287
560
|
}
|
|
288
561
|
}
|
|
289
|
-
return this
|
|
562
|
+
return this.passages
|
|
290
563
|
}
|
|
291
564
|
|
|
292
565
|
regex(text) {
|
package/src/abbr.js
CHANGED
|
@@ -10,6 +10,7 @@ parser.options({
|
|
|
10
10
|
invalid_passage_strategy: "include",
|
|
11
11
|
invalid_sequence_strategy: "include",
|
|
12
12
|
single_chapter_1_strategy: "verse",
|
|
13
|
+
sequence_combination_strategy: "combine",
|
|
13
14
|
})
|
|
14
|
-
const result = parser.parse("
|
|
15
|
+
const result = parser.parse("John 3:1-3")
|
|
15
16
|
dump(result.getPassages())
|