codexparser 0.0.33 → 0.0.34

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.
@@ -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, 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,89-40 Heb 11.20 Heb. 12.17 Jonah 3"
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
- console.log(passages)
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.33",
3
+ "version": "0.0.34",
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(", "))
@@ -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 judeRegex = /(?:[j|J][d|ude]+.?\s?\d+)/gim
27
- const jude = text.match(judeRegex)
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,106 @@ class CodexParser {
43
39
  */
44
40
  parse(reference) {
45
41
  if (!reference) {
46
- return null // return null if no reference is provided
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
+ console.log("First Passage, First Log: ", firstPassage)
86
+ for (let j = 0; j < booksWithResults[i].length; j++) {
87
+ const passage = booksWithResults[i][j]
88
+ if (passage.type === "integer") {
89
+ if (firstPassage.type === "range") {
90
+ if (passage.start.c !== passage.end.c) {
91
+ firstPassage.to.verses.push(passage.start.v)
92
+ } else {
93
+ firstPassage.verses.push(passage.start.v)
94
+ }
95
+ firstPassage.original += ", " + passage.start.v
96
+ } else {
97
+ if (passage.start.v !== passage.end.v) {
98
+ firstPassage.verses.push(passage.start.v)
99
+ firstPassage.verses.push(passage.end.v)
100
+ firstPassage.original += ", " + passage.start.v + ", " + passage.end.v
101
+ } else {
102
+ firstPassage.verses.push(passage.start.v)
103
+ firstPassage.original += ", " + passage.start.v
104
+ }
105
+ }
106
+ } else if (passage.type === "range") {
107
+ if (firstPassage.chapter === passage.start.c) {
108
+ firstPassage.verses.push(passage.start.v + "-" + passage.end.v)
109
+ }
110
+ } else {
111
+ const subPassage = {
112
+ original: passage.osis,
113
+ book: this.bookify(passage.start.b),
114
+ chapter: passage.start.c,
115
+ type: passage.type,
116
+ entities: passage.entities,
117
+ }
118
+ if (passage.type === "range") {
119
+ if (passage.start.c !== passage.end.c) {
120
+ subPassage.to = {
121
+ book: this.bookify(passage.end.b),
122
+ chapter: passage.end.c,
123
+ verses: [passage.end.v],
124
+ }
125
+ } else {
126
+ subPassage.verses =
127
+ passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
128
+ }
129
+ } else {
130
+ subPassage.verses =
131
+ passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
132
+ }
133
+ this.passages.push(subPassage)
134
+ }
135
+ }
136
+ console.log(firstPassage)
137
+ this.passages.push(firstPassage)
138
+ //console.log(this.passages)
139
+ }
140
+ //console.log(booksWithResults)
141
+ /* for (let i = 0; i < this.found.length; i++) {
51
142
  const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
52
143
  const book = this.found[i].match(this.bookRegex)
53
144
  if (book === null) continue
@@ -63,7 +154,6 @@ class CodexParser {
63
154
  verse = []
64
155
  }
65
156
  }
66
- console.log(verse)
67
157
  const passage = {
68
158
  original: this.found[i].replace(/([.,])\1*$/, "").trim(),
69
159
  book: this.bookify(book),
@@ -90,10 +180,18 @@ class CodexParser {
90
180
  }
91
181
 
92
182
  this.found = []
93
- return this.passages
183
+ return this.passages */
94
184
  }
95
185
  chapterify(chapter) {
96
- return chapter[0].replace(/[:\.]/, "").trim()
186
+ if (chapter.type === "range") {
187
+ return `${chapter.start.c} - ${chapter.end}`
188
+ }
189
+ }
190
+
191
+ versify(passage, type) {
192
+ if (type !== "range")
193
+ return passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
194
+ else return [passage.start.v + "-" + passage.end.v]
97
195
  }
98
196
 
99
197
  /**
@@ -103,10 +201,11 @@ class CodexParser {
103
201
  * @return {string|undefined} The full name of the book if found, otherwise undefined.
104
202
  */
105
203
  bookify(book) {
204
+ if(typeof book !== "string") {
205
+ book = book[0]
206
+ }
106
207
  let bookified
107
- book = book[0].charAt(0).toUpperCase() + book[0].slice(1)
108
208
  bookified = this.abbrevations[book]
109
-
110
209
  if (!bookified) {
111
210
  bookified = this.bible.new.find(
112
211
  (b) =>
@@ -137,6 +236,7 @@ class CodexParser {
137
236
  * @param {object} passage - A passage object
138
237
  */
139
238
  scripturize(passage) {
239
+ console.log(passage)
140
240
  const { book, chapter, verses, to } = passage
141
241
  const colon = verses.length !== 0 ? ":" : ""
142
242
  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|Song of Solomon|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
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 = /\b[:.](\d+(?:,?\s*?\d+?|-|–|—\d+)*)?\d+(?:[abcde])?(?:,\d+)*(?:,\s?\d+)?\b/gm
3
+ const verseRegex = /\b[:.].+\b/gm
4
4
  const chapterRange = /.?\s?(?:[-—–])\s?/gm
5
5
  const chapterRangeVerseRegex = /(?:.\d+)?/gm
6
6
  const chapterVerseRange =
7
- /(.?\s?\d+((?:[:.]\d+)?(\s?[-–—]\s?)?(?:\d+)(?:(,\s?\d+)*)?([:.]?\d+)?(,?\s?\d+[–—-]\s?\d+,?\d+)?)?(?:[:.]\d+)?(?:[abcde])?(?:,\d+)*(?:[-–—]\d?\s?)?)(?:[:.]\d+[–-—]\s?\d+,?\s?\d+)?(?:(\d+)?,\s?\d+)?/gim
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 text = parser.parse("Joel 2:10, 11")
5
- console.log(text)
4
+ const scripture = "Hos 1:1-3, 8"
5
+ console.log(scripture)
6
+ parser.parse(`${scripture}. Please turn in your Bibles.`)