scripture-guide 1.0.39 → 1.0.41

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,27 +1,5 @@
1
1
 
2
2
 
3
- const prepareBlacklist = (lang_extras) => {
4
- var blacklist = [];
5
- blacklist.push("\\d{4,}"); // 4 Digit references
6
- blacklist.push("^Ch\\. \\d+"); //Chapter with no book
7
- blacklist.push("\\w\\w\\d\\d"); //Words with numbers together KGURO43KEAJFK
8
-
9
- //Oneoff Blacklist
10
- blacklist.push("\\bro \\d+\\b"); //lowecase letters followed by numbers
11
- blacklist.push("\\bETH \\d+\.\\d+\\b");
12
- blacklist.push("\\b(BC|AD|BCE)[––—−]+\\d+\\b"); //550 BC–330 BC
13
- blacklist.push("\\b(AC3|PS2|PS3|PS4)\\b"); //Common file extentions
14
- blacklist.push("\\b(ps|PS)[1-9]\\b"); //Common file extentions'
15
-
16
- //Increase strictness for abbreviations
17
- blacklist.push("\\b[a-z][a-z] [0-9]"); //lowercase 2-letter abbreviation
18
-
19
-
20
- var blacklist_pattern = new RegExp("(" + blacklist.join("|") + ")", 'g');
21
-
22
- return blacklist_pattern;
23
- }
24
-
25
3
 
26
4
  const findMatchingBooks = (content,books) => {
27
5
  const matchingBooks = books.filter(i=>(new RegExp(i,"ig")).test(content));
@@ -30,25 +8,63 @@ const findMatchingBooks = (content,books) => {
30
8
 
31
9
  const findMatches = (content,books,lang_extra) => {
32
10
 
11
+ const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
33
12
  const preBookMatch = lang_extra.book || `(First|I|1|1st|Second|II|2|2nd|Third|III|3|3rd|Fourth|IV|4|4th)*\\s*(books* of)*\\s*`;
34
13
  const matchingBooks = findMatchingBooks(content,books);
35
14
  const postBookMatch = lang_extra.chapter || "([0-9:.;,~ —–-])*[0-9]+";
36
- const matchesWithReferences = matchingBooks.map(bookMatch=>{
37
- const patternString = preBookMatch + bookMatch + postBookMatch;
15
+ const fullBookMatches = matchingBooks.map(bookMatch=>{
16
+ const patternString = preBookMatch + bookMatch ;
38
17
  const pattern = (new RegExp(patternString,"ig"));
39
18
  const stringMatch = pattern.test(content) ? patternString : null;
40
19
  //console.log({pattern,content,stringMatch});
41
20
  return stringMatch;
42
21
  }).filter(x=>!!x);
43
22
 
44
-
45
23
 
46
- // Ensure the match ends with a number
47
- // Also remove duplicates that may have been created by the postBookMatch
48
- return matchesWithReferences.map(string=>{
24
+ const bookSubStrings = fullBookMatches.map(bookMatch=>{
25
+ const matchCount = content.match(new RegExp(bookMatch,"ig")).length;
26
+ const substrings = content.match(new RegExp(bookMatch,"ig")).flat();
27
+ return substrings;
28
+ }).flat().reduce((prev,current)=>{
29
+ if(prev.includes(current)) return prev;
30
+ return [...prev,current]
31
+ },[]).filter(i=>!!i).map(substring=>{
32
+ let positions = [];
33
+ let index = content.indexOf(substring);
34
+ while (index != -1) {
35
+ positions.push(index);
36
+ index = content.indexOf(substring, index + 1);
37
+ } return [substring,positions];
38
+ });
39
+
40
+
41
+ const possiblyOverlappingMatches = bookSubStrings.map(([substring,positions])=>{
42
+ return positions.map(i=>{
43
+ const pattern = new RegExp(substring+postBookMatch,"ig");
44
+ const match = content.slice(i).match(pattern)?.[0]?.replace(tail,"").trim();
45
+ if(!match) return null;
46
+ const len = match.length;
47
+ const pos = i;
48
+ const [posIn, posOut] = [pos,pos+len];
49
+ //console.log({content:content.slice(i),pattern,match,posIn,posOut});
50
+ return [match,posIn,posOut];
51
+ }
52
+ )}).flat().filter(i=>!!i);
53
+
54
+
55
+
56
+ const matchesWithReferences = possiblyOverlappingMatches.map(([string,start,end])=>{
57
+ const overLappingItems = possiblyOverlappingMatches.filter(([s,s1,e1])=>s!==string && s1<end && e1>end);
58
+ const hasOverlap = overLappingItems.length > 0;
59
+ const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s,s1,e1])=>s1)) : end;
60
+ const newString = content.slice(start,newEnd);
61
+ return newString.replace(tail,"").trim();
62
+ }).filter(i=>!!i);
63
+
64
+ const matches = matchesWithReferences.map(string=>{
49
65
  const pattern = (new RegExp(string,"ig"));
50
- const tail = lang_extra.tail || /[^0-9]+$/;
51
66
  const matches = content.match(pattern)?.map(i=>i.trim().replace(tail,""));
67
+ //console.log({string,matches,tail});
52
68
  return matches;
53
69
  }).flat()
54
70
  .reduce((prev,current)=>{
@@ -58,43 +74,44 @@ const findMatches = (content,books,lang_extra) => {
58
74
 
59
75
 
60
76
 
61
-
62
- //TODO: Process on a language by language basis
63
- // 2. Prebook JST
64
- // 3. Prechapter (, chapter, ch)
65
- // 4. Preverse (, verse, v, vv, vv, vvv)
66
- // 5. Joiners (,;and, &, cf, etc)
77
+ return matches;
67
78
  }
68
79
 
69
80
 
70
81
 
71
- function findMatchIndexes(content, matches,lookupReference) {
82
+ function findMatchIndexes(content, matches,lookupReference, lang_extra) {
83
+ const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
72
84
  const indexes = matches.map(i=>{
73
85
  const length = i.length;
74
86
  let positions = [];
75
87
  let strPos = content.indexOf(i);
88
+
76
89
  while (strPos != -1) {
77
90
  positions.push(strPos);
78
91
  strPos = content.indexOf(i, strPos + 1);
79
92
  }
80
- return positions.map(i=>[i,i+length]);
93
+ return positions.map(i=>[i,i+length+2]);
81
94
  }).flat()
82
- .filter(a=>{
95
+ .map(a=>{
83
96
 
84
- const substring = content.substring(a[0],a[1]);
97
+ const substring = content.substring(a[0],a[1]).replace(tail,"").trim();
85
98
  const charRightBeforeMatch = content.substring(a[0]-1,a[0]);
86
- if(!/(^|\s|\W)/.test(charRightBeforeMatch)) return false;
99
+ const leadingCharIsInvalid = !/^(\s|\W|)$/.test(charRightBeforeMatch);
100
+ // console.log({substring, charRightBeforeMatch, leadingCharIsInvalid});
101
+ if(leadingCharIsInvalid) return false;
87
102
  const verse_ids = lookupReference(substring).verse_ids;
88
- // console.log({a,substring,verse_ids});
89
- if(verse_ids.length > 0) return true;
90
-
103
+ //console.log({a,substring,verse_ids});
104
+ if(verse_ids.length > 0) return [a[0],a[0]+substring.length];
91
105
 
92
106
  return false;
93
107
  })
94
- .sort((a, b) => a[0] - b[0]);
95
-
96
-
97
-
108
+ .filter(i=>!!i)
109
+ .sort((a, b) => a[0] - b[0])
110
+ .map(([start, end], index, array) => {
111
+ const nextStart = array[index+1]?.[0] || null;
112
+ end = nextStart ? Math.min(end,nextStart) : end;
113
+ return [start,end];
114
+ });
98
115
  if(!indexes.length) return false;
99
116
 
100
117
 
@@ -149,9 +166,9 @@ const processReferenceDetection = (content,books,lang_extra,lookupReference,call
149
166
  {
150
167
  lang_extra = lang_extra || {};
151
168
  const matches = findMatches(content,books,lang_extra);
169
+
152
170
 
153
-
154
- const matchIndeces = findMatchIndexes(content,matches,lookupReference);
171
+ const matchIndeces = findMatchIndexes(content,matches,lookupReference,lang_extra);
155
172
  if(!matchIndeces) return content;
156
173
 
157
174
 
@@ -162,6 +179,8 @@ const processReferenceDetection = (content,books,lang_extra,lookupReference,call
162
179
  return [...prev,gap];
163
180
  },[]);
164
181
 
182
+ const gapStrings = gapsBetweenIndeces.map(([start,end])=>content.substring(start,end).trim());
183
+
165
184
 
166
185
 
167
186
 
@@ -236,69 +255,7 @@ const processReferenceDetection = (content,books,lang_extra,lookupReference,call
236
255
  }
237
256
 
238
257
 
239
- const preparePattern = (booklist,wordBreak,lang_extras) => {
240
-
241
-
242
- wordBreak = wordBreak || "";
243
- lang_chapter = lang_extras?.chapter || "";
244
- lang_verse = lang_extras?.verse || "";
245
-
246
- var bookregex = booklist.map(b=>{
247
- return b[0];
248
- });
249
-
250
- //Combine Books
251
- const books = "(?:" + bookregex.join("|") + ")\\s*"; // \\(*
252
-
253
- //Books that have a digit before them
254
- var numbooks = [];
255
- numbooks.push("ne");
256
- numbooks.push("sam");
257
- numbooks.push("ki*n*gs");
258
- numbooks.push("chr");
259
- numbooks.push("cor");
260
- numbooks.push("ti");
261
- numbooks.push("thes");
262
- numbooks.push("pet");
263
- numbooks.push("jo*h*n");
264
-
265
-
266
- //Meta data components
267
- var jst = "(?:[, —\\-]*(?:Joseph Smith[']*s* Translation *o*f*|\\(Joseph Smith[']*s* Translation *o*f*\\)|jst|\\(jst\\))[, \\—\\-)]*)*";
268
- var ordinals = `(?:[I1-4]*(?:3rd|1st|2n*d|4th|first|sec*o*n*d*\\.*|third|fourt*h*)* *${wordBreak})*`;
269
- var booksof = "(?:\\s*books* of\\s*)*";
270
- var prechapter = "(?:\\s|\\-|–|,)*";
271
- var chapter = `(?:,*\\s*` + ordinals + `${wordBreak}cha*p*t*e*r*s*\\.*,*\\s*)`;
272
- var verse = `(?:,*\\s*` + ordinals + `${wordBreak}v*ve*r*s*e*s*\\.*,*\\s*)`;
273
- var versenums = "\\s*[0-9]+"; //[a-f]*
274
- var joiners = "(?:[,;&\\/](?:\\s*and\\s*)*\\s*(?!$))*";
275
- var bumper = "(?![^<>]*>)"; //prevents matching inside of quotes
276
-
277
-
278
- //Punctuations, etc
279
- var punct = [];
280
- punct.push("\\s*[:\\-\\.~–—]" + versenums); //[a-z]{0,1} //colons,dots and dashes
281
- punct.push("\\s*(?:" + chapter + "|" + verse + ")" + versenums); //spelled out chapter and verse words
282
- punct.push("\\s*(?:;|,|,* *and|&amp;|&| *to *)\\s*[1-9]\\d*(?!\\s*\\.*(" + numbooks.join("|") + "))"); //passage breakers (a new book may appear after)
283
- //add language overrides
284
- if(lang_chapter) punct.push(lang_chapter);
285
- if(lang_verse) punct.push(lang_verse);
286
- //if(Array.isArray(lang_extras)) punct = [...punct, ...lang_extras];
287
-
288
- //combine punctuation
289
- var punct = "(?:[1-9]\\d*(?:" + punct.join("|") + ")*)";
290
-
291
- //Full Regex
292
- var match = bumper + "((?:(?:" + jst + `${wordBreak}` + ordinals + booksof + books + prechapter + chapter + "*" + punct + jst + ")" + joiners + ")+)";
293
- var pattern = new RegExp(match, 'gi');
294
-
295
- return pattern;
296
-
297
- }
298
-
299
258
 
300
259
  module.exports = {
301
- prepareBlacklist,
302
- preparePattern,
303
260
  processReferenceDetection
304
261
  }
@@ -35,7 +35,7 @@ module.exports = {
35
35
  chapter:"([장절과와및0-9:;,~\\s—–-]|부터|그리고|또는*)*[0-9장절]+",
36
36
  verse:"절",
37
37
  joiners: ["^[;, ]*(또는*|그리고|비교|과|와)*$"],
38
- tail: "[장절0-9]+"
38
+ tail: "[^장절0-9]+$"
39
39
  },
40
40
  },
41
41
  de:{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripture-guide",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "A utility for biblical and scripture reference parsing that enables structured queries based on strings of traditional scripture references (e.g. John 3:16). ",
5
5
  "main": "scriptures-compiled.js",
6
6
  "scripts": {
package/test/data/en.txt CHANGED
@@ -5,4 +5,6 @@ It talks about the consequences of the fall of Adam and Eve. Before the fall, if
5
5
  See John3:16 and, but not First John 1:9 for the same concept of the fall and the atonement.
6
6
  The fruit mentioned in 1 Nephi 8:9-12 represents something desirable and joyous. It is described as being sweet and white, surpassing any other fruit in its goodness and purity. In the book of Genesis, there is mention of the tree of life and the tree of the knowledge of good and evil (Genesis 2:9, 3:6). These trees represent different choices and paths that humans can take. The fruit in Lehi’s dream could be seen as a representation of the blessings and joy that come from choosing the path of righteousness and partaking of the goodness of God. In the book of Revelation, there are references to the tree of life as well (Revelation 2:7, 22:2). This tree is associated with eternal life and the blessings of God. So, the fruit in Lehi’s dream may also symbolize the blessings of eternal life and joy that come from following the teachings of Jesus Christ.
7
7
  In accordance with David’s last words at 2 Sam 23.3 (cf. Mos 23.8; 29.16). The Davidic reference may have been included as a conciliatory gesture to his descendants among the Mulekites. The reading in P (“thereby”) implies that keeping the commandments leads to rejoicing and love.
8
- *As Jacob’s priestly lineage comes to an end, the transferal of the plates to Benjamin means that both the Large and Small Plates of Nephi are in the possession of the Nephite kings; cf. WoM 1.10. Amaleki’s reference to spiritual gifts and his assertion about the sources of good and evil will be repeated at Moro 7.12, 16–17; 10.13–16; cf. Alma 5.40. The order of gifts listed generally reflects 1 Cor 12.10.
8
+ As Jacob’s priestly lineage comes to an end, the transferal of the plates to Benjamin means that both the Large and Small Plates of Nephi are in the possession of the Nephite kings; cf. WoM 1.10. Amaleki’s reference to spiritual gifts and his assertion about the sources of good and evil will be repeated at Moro 7.12, 16–17; 10.13–16; cf. Alma 5.40. The order of gifts listed generally reflects 1 Cor 12.10.
9
+ Consistently D&C 3:16-17 no "Samites" Mormon 1:8 mentioned across the board in Restoration scripture; cf. Jacob 1:13; 4 Nephi 1:38; Mormon 1:8; D&C 3:17-18
10
+ The Nephites thought of themselves as living on an island, and they believed that other groups of Israelites had been led away by God to other islands as well; see 1 Ne 19.10,15–16;21.1,8;22.3–4;2 Ne 10.7–8;29.7. Note also the mention of “isles” in Isa 51.5, which Jacob quoted at 2 Ne 8.5.
package/test/data/vn.txt CHANGED
@@ -11,3 +11,4 @@ Giảng dạy phụ thân của Vua La Mô Ni, AnMa 22:1–26.
11
11
  Xem Gioan 3:16 và, nhưng không phải là 1 Gioan 1:9 cho cùng một khái niệm về sự rơi rớt và sự chuộc tội.
12
12
  Trong đoạn Kinh thánh này, điểm chính là về trạng thái kinh hãi và run sợ của Lê Hi khi ông cầu nguyện và một cột lửa xuất hiện trước mặt ông. Điều này làm cho ông cảm thấy choáng ngợp và run sợ vô cùng. Điều này cho thấy sự mạnh mẽ và thiêng liêng của trải nghiệm này. Có một số tham chiếu trong Kinh thánh khác có thể giúp hiểu rõ hơn về hiện tượng này. Ví dụ, trong Xuất Ê Díp Tô 3:2, Thiên-sứ của Đức Giê-hô-va hiện ra trong một ngọn lửa giữa bụi gai, và cột lửa đó không tàn. (Xuất Ê Díp Tô 3:2) Điều tương tự cũng xảy ra trong Lê Vi 9:24 khi lửa từ trước mặt Đức Giê-hô-va thiêu hủy của-lễ thiêu và mỡ trên bàn thờ. (Lê Vi 9:24) Những hiện tượng này cho thấy sự hiện diện thiêng liêng và quyền năng của Chúa. Chúng là cách Chúa thể hiện sự lựa chọn và giao ước của Ngài với những người mà Ngài đã gọi. Trong trường hợp của Lê Hi, cột lửa xuất hiện trước mặt ông có thể cho thấy rằng ông đã được chọn và giao ước để truyền thông điệp của Chúa và dẫn dắt dân chúng. Điểm chính của đoạn này là sự mạnh mẽ và tác động mạnh mẽ của kinh nghiệm kỳ lạ này đối với Lê Hi. Nó gợi lên sự sợ hãi và kinh hãi của ông, đồng thời cũng cho thấy sự hiện diện và quyền năng của Chúa trong cuộc sống của con người.
13
13
  Trong đoạn này, chúng ta đang đọc về Lê Hi, một người đàn ông sống tại Giê Ru Sa Lem. Sau khi nhận được lời cảnh báo về sự hủy diệt sắp xảy ra của Ba Bi Lôn, Lê Hi đã cầu nguyện và có một trải nghiệm đặc biệt. Ông trở về nhà và nằm xuống giường, trong tâm trạng cảm thấy rung động và chan hòa Thánh Linh . Trong trạng thái này, Lê Hi có một tầm nhìn đặc biệt, ông nhìn thấy Chúa, Thiên thần và một vị cao quý cùng mười hai môn đệ. Chúa Giê-xu trao cho Lê Hi một quyển sách xác nhận sự phá hủy của Giê Ru Sa Lem trong tương lai và sự chiếm đóng của Ba Bi Lôn. Lê Hi trở thành một ngôn sứ và đi ra ngoài để thông báo tầm nhìn mà ông đã thấy . Điều này cho thấy tầm nhìn của Lê Hi có ý nghĩa quan trọng trong việc cảnh báo người dân về mối nguy hiểm đang đến gần. Nó cũng cho thấy sự quan tâm và lòng trắc ẩn của Chúa đối với dân của Giê Ru Sa Lem. Điều này có thể liên kết với những trạng thái tâm hồn khác của các nhân vật trong Kinh Thánh, như sự lo âu của Do Thái khi nghe lời kêu gọi hối cải của Lê Hi (1 Nê Phi 17:47) và tâm hồn buồn phiền của Lê Hi vì dân của Giê Ru Sa Lem (1 Nê Phi 19:20). Nhưng điều quan trọng là chúng ta hãy tìm hiểu và suy ngẫm về những thông điệp và lời cảnh báo mà Chúa đã truyền qua các nhân vật và trải nghiệm của họ trong Kinh Thánh.
14
+ Các tham chiếu khác trong Kinh Thánh, như 1 Nê Phi 5:4, 1 Nê Phi 11:14, An Ma 36:22, Hê La Man 5:48 và Giáo Lý và Giao Ước 137, có thể cung cấp thêm thông tin và phần nào làm sáng tỏ thêm về trải nghiệm của Lê Hi.
package/test-detect.js CHANGED
@@ -22,7 +22,7 @@ for(const lang of langs){
22
22
  if(lang!=="en") setLanguage(lang);
23
23
  let lines = fs.readFileSync(`${__dirname}/test/data/${lang}.txt`,"utf-8").split("\n").map(i=>i.trim()).filter(x=>!!x);
24
24
  const hasAsterix = lines.some(i=>/^[*]/.test(i));
25
- if(hasAsterix) lines = lines.filter(i=>/^[*]/.test(i)).map(i=>i.replace(/^[*]/,""))
25
+ if(hasAsterix) lines = lines.filter(i=>/^[*]/.test(i)).map(i=>i.replace(/^[*]/,"").trim())
26
26
  for(const line of lines){
27
27
  const i = detectReferences(line,callback);
28
28
  console.log([i]);