codexparser 0.0.33 → 0.0.35
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/all-scripture-test.js +4 -14
- package/bcv_test.js +14 -0
- package/package.json +4 -1
- package/passage-generator.js +25 -0
- package/src/CodexParser.js +114 -16
- package/src/abbr.js +0 -2
- package/src/regex.js +3 -3
- package/sub-verse-scripture-test.js +3 -2
package/all-scripture-test.js
CHANGED
|
@@ -2,19 +2,9 @@ const CodexParser = require("./src/CodexParser.js")
|
|
|
2
2
|
|
|
3
3
|
const parser = new CodexParser()
|
|
4
4
|
const text =
|
|
5
|
-
"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,
|
|
6
|
-
const single = "Ge 27.27-29,
|
|
5
|
+
"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"
|
|
6
|
+
const single = "Ge 27.27-29,32-40 Heb 11.20 Heb. 12.17 Jonah 3"
|
|
7
7
|
const jd = "Jd. 5"
|
|
8
8
|
const cor = "Hos 1:1-3, 8 Song of Solomon 1:2, Song of Songs 2:2. Ezek 17:3. Ezekiel 17:3"
|
|
9
|
-
const passages = parser.parse(single)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const jude = parser.parse(jd)
|
|
13
|
-
console.log(jude)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const fullText = parser.parse(text)
|
|
17
|
-
console.log(fullText)
|
|
18
|
-
|
|
19
|
-
const textParser = parser.parse(cor)
|
|
20
|
-
console.log(textParser)
|
|
9
|
+
const passages = parser.parse(single + " " + text + " " + jd + " " + cor)
|
|
10
|
+
//const passages = parser.parse('Romans 8:9,12,15,17,20,28')
|
package/bcv_test.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const bcv_parser = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
|
|
2
|
+
const text =
|
|
3
|
+
"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
|
+
const single = "Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3"
|
|
5
|
+
const jd = "Jd. 5"
|
|
6
|
+
const cor = "Hos 1:1-3, 8 Song of Solomon 1:2, Song of Songs 2:2. Ezek 17:3. Ezekiel 17:3"
|
|
7
|
+
|
|
8
|
+
const parser = new bcv_parser()
|
|
9
|
+
const textParser = parser.parse(text + single + jd + cor)
|
|
10
|
+
const passages = textParser.parsed_entities()
|
|
11
|
+
|
|
12
|
+
passages.forEach((passage) => {
|
|
13
|
+
console.log(passage.entities)
|
|
14
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
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": {
|
|
@@ -20,5 +20,8 @@
|
|
|
20
20
|
"path": "^0.12.7",
|
|
21
21
|
"webpack": "^5.90.3",
|
|
22
22
|
"webpack-cli": "^5.1.4"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"bible-passage-reference-parser": "^2.0.1"
|
|
23
26
|
}
|
|
24
27
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function generateScriptureCombinations(book, chapters, versesPerChapter) {
|
|
2
|
+
let scriptureCombinations = []
|
|
3
|
+
|
|
4
|
+
for (let chapter = 1; chapter <= chapters; chapter++) {
|
|
5
|
+
for (let verse = 1; verse <= versesPerChapter[chapter - 1]; verse++) {
|
|
6
|
+
// Single verse
|
|
7
|
+
scriptureCombinations.push(`${book} ${chapter}:${verse}`)
|
|
8
|
+
// Verse ranges within a chapter
|
|
9
|
+
for (let endVerse = verse + 1; endVerse <= versesPerChapter[chapter - 1]; endVerse++) {
|
|
10
|
+
scriptureCombinations.push(`${book} ${chapter}:${verse}-${endVerse}`)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Chapter ranges
|
|
14
|
+
for (let endChapter = chapter + 1; endChapter <= chapters; endChapter++) {
|
|
15
|
+
scriptureCombinations.push(`${book} ${chapter}:${versesPerChapter[chapter - 1]}-${endChapter}:1`)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return scriptureCombinations
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Example usage for the book of Genesis (assuming 50 chapters and a fixed number of verses per chapter for simplicity)
|
|
23
|
+
const genesisVersesPerChapter = new Array(50).fill(30) // Replace with actual verse count per chapter
|
|
24
|
+
const genesisCombinations = generateScriptureCombinations("Genesis", 50, genesisVersesPerChapter)
|
|
25
|
+
console.log(genesisCombinations.join(", "))
|
package/src/CodexParser.js
CHANGED
|
@@ -2,6 +2,7 @@ const bible = require("./bible")
|
|
|
2
2
|
const { bookRegex, chapterRegex, verseRegex, scripturesRegex } = require("./regex")
|
|
3
3
|
const abbrevations = require("./abbr")
|
|
4
4
|
const toc = require("./toc")
|
|
5
|
+
const crawler = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
|
|
5
6
|
|
|
6
7
|
class CodexParser {
|
|
7
8
|
constructor() {
|
|
@@ -14,6 +15,9 @@ class CodexParser {
|
|
|
14
15
|
this.scripturesRegex = scripturesRegex
|
|
15
16
|
this.abbrevations = abbrevations
|
|
16
17
|
this.toc = toc
|
|
18
|
+
this.crawler = new crawler({
|
|
19
|
+
sequence_combination_strategy: "separate",
|
|
20
|
+
})
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -23,16 +27,8 @@ class CodexParser {
|
|
|
23
27
|
* @return {array} The found passages from the text.
|
|
24
28
|
*/
|
|
25
29
|
scan(text) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
this.found = text.match(this.scripturesRegex)
|
|
29
|
-
if (!this.found) {
|
|
30
|
-
this.found = []
|
|
31
|
-
}
|
|
32
|
-
if (jude) {
|
|
33
|
-
this.found.push(...jude)
|
|
34
|
-
}
|
|
35
|
-
return this.found
|
|
30
|
+
const passages = this.crawler.parse(text).parsed_entities()
|
|
31
|
+
this.found.push(...passages.flatMap((passage) => passage.entities))
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
/**
|
|
@@ -43,11 +39,104 @@ class CodexParser {
|
|
|
43
39
|
*/
|
|
44
40
|
parse(reference) {
|
|
45
41
|
if (!reference) {
|
|
46
|
-
|
|
42
|
+
throw new Error("Parse error (parse(), line 46): reference is undefined")
|
|
47
43
|
}
|
|
48
44
|
this.passages = []
|
|
49
45
|
this.scan(reference)
|
|
46
|
+
const books = []
|
|
50
47
|
for (let i = 0; i < this.found.length; i++) {
|
|
48
|
+
books.push(this.found[i].start.b)
|
|
49
|
+
}
|
|
50
|
+
const uniqueBooks = [...new Set(books)]
|
|
51
|
+
const booksWithResults = []
|
|
52
|
+
//TODO: Need to loop through and create an array of all the same passage
|
|
53
|
+
// in order to be able to identify if comma separated verses goes with it or not.
|
|
54
|
+
for (const book of uniqueBooks) {
|
|
55
|
+
const found = this.found.filter((passage) => passage.start.b === book)
|
|
56
|
+
booksWithResults.push(found)
|
|
57
|
+
}
|
|
58
|
+
//console.log(booksWithResults)
|
|
59
|
+
for (let i = 0; i < booksWithResults.length; i++) {
|
|
60
|
+
const initialPassage = booksWithResults[i].shift()
|
|
61
|
+
const firstPassage = {
|
|
62
|
+
original: initialPassage.osis,
|
|
63
|
+
book: this.bookify(initialPassage.start.b),
|
|
64
|
+
chapter: initialPassage.start.c,
|
|
65
|
+
type: initialPassage.type,
|
|
66
|
+
entities: initialPassage.entities,
|
|
67
|
+
}
|
|
68
|
+
if (initialPassage.type === "range") {
|
|
69
|
+
if (initialPassage.start.c !== initialPassage.end.c) {
|
|
70
|
+
firstPassage.verses = [initialPassage.start.v]
|
|
71
|
+
firstPassage.to = {
|
|
72
|
+
book: this.bookify(initialPassage.end.b),
|
|
73
|
+
chapter: initialPassage.end.c,
|
|
74
|
+
verses: [initialPassage.start.v],
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
firstPassage.verses = [initialPassage.start.v + "-" + initialPassage.end.v]
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
firstPassage.verses =
|
|
81
|
+
initialPassage.start.v !== initialPassage.end.v
|
|
82
|
+
? [initialPassage.start.v, initialPassage.end.v]
|
|
83
|
+
: [initialPassage.start.v]
|
|
84
|
+
}
|
|
85
|
+
for (let j = 0; j < booksWithResults[i].length; j++) {
|
|
86
|
+
const passage = booksWithResults[i][j]
|
|
87
|
+
if (passage.type === "integer") {
|
|
88
|
+
if (firstPassage.type === "range") {
|
|
89
|
+
if (passage.start.c !== passage.end.c) {
|
|
90
|
+
firstPassage.to.verses.push(passage.start.v)
|
|
91
|
+
} else {
|
|
92
|
+
firstPassage.verses.push(passage.start.v)
|
|
93
|
+
}
|
|
94
|
+
firstPassage.original += ", " + passage.start.v
|
|
95
|
+
} else {
|
|
96
|
+
if (passage.start.v !== passage.end.v) {
|
|
97
|
+
firstPassage.verses.push(passage.start.v)
|
|
98
|
+
firstPassage.verses.push(passage.end.v)
|
|
99
|
+
firstPassage.original += ", " + passage.start.v + ", " + passage.end.v
|
|
100
|
+
} else {
|
|
101
|
+
firstPassage.verses.push(passage.start.v)
|
|
102
|
+
firstPassage.original += ", " + passage.start.v
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else if (passage.type === "range") {
|
|
106
|
+
if (firstPassage.chapter === passage.start.c) {
|
|
107
|
+
firstPassage.verses.push(passage.start.v + "-" + passage.end.v)
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const subPassage = {
|
|
111
|
+
original: passage.osis,
|
|
112
|
+
book: this.bookify(passage.start.b),
|
|
113
|
+
chapter: passage.start.c,
|
|
114
|
+
type: passage.type,
|
|
115
|
+
entities: passage.entities,
|
|
116
|
+
}
|
|
117
|
+
if (passage.type === "range") {
|
|
118
|
+
if (passage.start.c !== passage.end.c) {
|
|
119
|
+
subPassage.to = {
|
|
120
|
+
book: this.bookify(passage.end.b),
|
|
121
|
+
chapter: passage.end.c,
|
|
122
|
+
verses: [passage.end.v],
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
subPassage.verses =
|
|
126
|
+
passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
subPassage.verses =
|
|
130
|
+
passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
|
|
131
|
+
}
|
|
132
|
+
this.passages.push(subPassage)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.passages.push(firstPassage)
|
|
136
|
+
//console.log(this.passages)
|
|
137
|
+
}
|
|
138
|
+
//console.log(booksWithResults)
|
|
139
|
+
/* for (let i = 0; i < this.found.length; i++) {
|
|
51
140
|
const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
|
|
52
141
|
const book = this.found[i].match(this.bookRegex)
|
|
53
142
|
if (book === null) continue
|
|
@@ -63,7 +152,6 @@ class CodexParser {
|
|
|
63
152
|
verse = []
|
|
64
153
|
}
|
|
65
154
|
}
|
|
66
|
-
console.log(verse)
|
|
67
155
|
const passage = {
|
|
68
156
|
original: this.found[i].replace(/([.,])\1*$/, "").trim(),
|
|
69
157
|
book: this.bookify(book),
|
|
@@ -90,10 +178,18 @@ class CodexParser {
|
|
|
90
178
|
}
|
|
91
179
|
|
|
92
180
|
this.found = []
|
|
93
|
-
return this.passages
|
|
181
|
+
return this.passages */
|
|
94
182
|
}
|
|
95
183
|
chapterify(chapter) {
|
|
96
|
-
|
|
184
|
+
if (chapter.type === "range") {
|
|
185
|
+
return `${chapter.start.c} - ${chapter.end}`
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
versify(passage, type) {
|
|
190
|
+
if (type !== "range")
|
|
191
|
+
return passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
|
|
192
|
+
else return [passage.start.v + "-" + passage.end.v]
|
|
97
193
|
}
|
|
98
194
|
|
|
99
195
|
/**
|
|
@@ -103,10 +199,11 @@ class CodexParser {
|
|
|
103
199
|
* @return {string|undefined} The full name of the book if found, otherwise undefined.
|
|
104
200
|
*/
|
|
105
201
|
bookify(book) {
|
|
202
|
+
if(typeof book !== "string") {
|
|
203
|
+
book = book[0]
|
|
204
|
+
}
|
|
106
205
|
let bookified
|
|
107
|
-
book = book[0].charAt(0).toUpperCase() + book[0].slice(1)
|
|
108
206
|
bookified = this.abbrevations[book]
|
|
109
|
-
|
|
110
207
|
if (!bookified) {
|
|
111
208
|
bookified = this.bible.new.find(
|
|
112
209
|
(b) =>
|
|
@@ -137,6 +234,7 @@ class CodexParser {
|
|
|
137
234
|
* @param {object} passage - A passage object
|
|
138
235
|
*/
|
|
139
236
|
scripturize(passage) {
|
|
237
|
+
console.log(passage)
|
|
140
238
|
const { book, chapter, verses, to } = passage
|
|
141
239
|
const colon = verses.length !== 0 ? ":" : ""
|
|
142
240
|
const parts = [book, chapter, colon, verses]
|
package/src/abbr.js
CHANGED
|
@@ -81,7 +81,6 @@ const abbrevations = {
|
|
|
81
81
|
"II Ch": "2 Chronicles",
|
|
82
82
|
Ezra: "Ezra",
|
|
83
83
|
Ezr: "Ezra",
|
|
84
|
-
Ez: "Ezra",
|
|
85
84
|
Neh: "Nehemiah",
|
|
86
85
|
Ne: "Nehemiah",
|
|
87
86
|
Esth: "Esther",
|
|
@@ -263,7 +262,6 @@ const abbrevations = {
|
|
|
263
262
|
"1K": "1 Corinthians",
|
|
264
263
|
"2K": "2 Corinthians",
|
|
265
264
|
G: "Galatians",
|
|
266
|
-
E: "Ephesians",
|
|
267
265
|
Ph: "Philippians",
|
|
268
266
|
Kol: "Colossians",
|
|
269
267
|
"1Th": "1 Thessalonians",
|
package/src/regex.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const bookRegex = /(?:(I+|1st|2nd|3rd|First|Second|Third|[123])\s)?(Gen|Ge|Gn|Exo|Ex|Exod|Lev|Le|Lv|Num|Nu|Nm|Nb|Deut|Dt|Josh|Jos|Jsh|Judg|Jdg|Jg|Jdgs|Rth|Ru|Sam|Samuel|Kings|Kgs|Kin|Chron|Chronicles|Ezra|Ezr|Neh|Ne|Esth|Es|Job|Job|Jb|Pslm|Ps|Psalms|Psa|Psm|Pss|Prov|Pr|Prv|Eccles|Ec|Song|So|Canticles|Song of Songs|SOS|
|
|
1
|
+
const bookRegex = /((?:(I+|1st|2nd|3rd|First|Second|Third|[123])\s)?(Gen|Ge|Gn|Exo|Ex|Exod|Lev|Le|Lv|Num|Nu|Nm|Nb|Deut|Dt|Josh|Jos|Jsh|Judg|Jdg|Jg|Jdgs|Rth|Ru|Sam|Samuel|Kings|Kgs|Kin|Chron|Chronicles|Ezra|Ezr|Ez|Neh|Ne|Esth|Es|Job|Job|Jb|Pslm|Ps|Psalms|Psa|Psm|Pss|Prov|Pr|Prv|Eccles|Ec|Song|So|Canticles|Song of Songs|SOS|Isa|Is|Jer|Je|Jr|Lam|La|Ezek|Eze|Ezk|Dan|Da|Dn|Hos|Ho|Joel|Joe|Jl|Amos|Am|Obad|Ob|Jnh|Jon|Micah|Mic|Nah|Na|Hab|Zeph|Zep|Zp|Haggai|Hag|Hg|Zech|Zec|Zc|Mal|Mal|Ml|Matt|Mt|Mrk|Mk|Mr|Luk|Lk|John|Jn|Jhn|Acts|Ac|Rom|Ro|Rm|Co|Cor|Corinthians|Gal|Ga|Ephes|Eph|Phil|Php|Col|Col|Th|Thes|Thess|Thessalonians|Ti|Tim|Timothy|Titus|Tit|Philem|Phm|Hebrews|Heb|He|James|Jas|Jm|Pe|Pet|Pt|Peter|Jn|Jo|Joh|Jhn|John|Jude|Jd|Jud|Jud|Rev|The Revelation|Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther|Job|Psalms|Psalm|Proverbs|Ecclesiastes|Song of Solomon|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|John|Revelation|Re|Ap))/gmi
|
|
2
2
|
const chapterRegex = /\b(?:\.?\s?\d+[:|\.]?)\b/gm
|
|
3
|
-
const verseRegex =
|
|
3
|
+
const verseRegex = /\b[:.].+\b/gm
|
|
4
4
|
const chapterRange = /.?\s?(?:[-—–])\s?/gm
|
|
5
5
|
const chapterRangeVerseRegex = /(?:.\d+)?/gm
|
|
6
6
|
const chapterVerseRange =
|
|
7
|
-
|
|
7
|
+
/.?(?:\d+)((?:[:.])(?:(\d+)?)(?:(,\s?\d+)*)?(?:\s?[-–—]\s?\d+)?(?:,\s?\d+(?:\s?[-–—]\s?\d+)?)?(?:[:.]\d+)?)?/gim
|
|
8
8
|
const scripturesRegex = new RegExp(`(${bookRegex.source})(${chapterVerseRange.source})`, "gmi")
|
|
9
9
|
module.exports.bookRegex = bookRegex
|
|
10
10
|
module.exports.chapterRegex = chapterRegex
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const CodexParser = require("./src/CodexParser.js")
|
|
2
2
|
|
|
3
3
|
const parser = new CodexParser()
|
|
4
|
-
const
|
|
5
|
-
console.log(
|
|
4
|
+
const scripture = "Hos 1:1-3, 8"
|
|
5
|
+
console.log(scripture)
|
|
6
|
+
parser.parse(`${scripture}. Please turn in your Bibles.`)
|