scripture-guide 1.0.28 → 1.0.30
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/data/scriptlang.js +9 -1
- package/data/scriptregex.js +3 -3
- package/package.json +1 -1
- package/scriptures-compiled.js +16 -7
- package/scriptures.js +18 -7
- package/test-lang.js +13 -9
package/data/scriptlang.js
CHANGED
|
@@ -157,7 +157,10 @@ module.exports = {
|
|
|
157
157
|
i = i.replace(/([\u3131-\uD79D]) *([0-9]+)/ig, "$1 $2장 ");
|
|
158
158
|
i = i.replace(/([0-9]+):([0-9]+)-([0-9]+)/g, "$1장 $2~$3절");
|
|
159
159
|
i = i.replace(/[–-]+/g,"~");
|
|
160
|
-
i = i.replace(/\s*:\s*([0-9~]+)/g, "
|
|
160
|
+
i = i.replace(/\s*:\s*([0-9~]+)/g, ":$1절");
|
|
161
|
+
i = i.replace(/([0-9]+):([0-9]+)/g, "$1장$2");
|
|
162
|
+
i = i.replace(/장:([0-9]+)/g, "장 $1");
|
|
163
|
+
|
|
161
164
|
i = i.replace(/;/g, "; ").replace(/\s+/g, " ").trim();
|
|
162
165
|
i = i.replace(/제\s*([3-4])장\s*니파이/g, "제$1니파이");
|
|
163
166
|
i = i.replace(/([0-9]+)장\s*([0-9]+)/g, "$1장 $2");
|
|
@@ -169,6 +172,11 @@ module.exports = {
|
|
|
169
172
|
i = i.replace(/(\d+) *장/g, "$1");
|
|
170
173
|
i = i.replace(/(\d+) *절/g, "$1");
|
|
171
174
|
i = i.replace(/([\u3131-\uD79D]) *(\d+)/ig, "$1 $2");
|
|
175
|
+
i = i.replace(/제 ([3-4])/g, "제$1");
|
|
176
|
+
i = i.replace(/조셉 스미스[—-]/g, "조셉 스미스—");
|
|
177
|
+
//replace commas with semicolons, unless a digit is on both sides of the comma
|
|
178
|
+
i = i.replace(/, *([^0-9])/g, "; $1");
|
|
179
|
+
console.log(i);
|
|
172
180
|
return i;
|
|
173
181
|
}
|
|
174
182
|
}
|
package/data/scriptregex.js
CHANGED
|
@@ -96,12 +96,12 @@ module.exports = {
|
|
|
96
96
|
["d(?:octrine)*\\.* *(?:&|&|and)* *c(?:ovenants)*(?:\\s*\\bSec(?:tion)*)*\\.*", "Doctrine and Covenants"],
|
|
97
97
|
["dee and see", "Doctrine and Covenants"],
|
|
98
98
|
|
|
99
|
-
["
|
|
99
|
+
["moses", "Moses"],
|
|
100
100
|
["Abra*\\.*(?:ham)*", "Abraham"],
|
|
101
101
|
["Jos(?:eph)*\\.* Smith(?:[–—\\- ]+Matthew)", "Joseph Smith\u2014Matthew"],
|
|
102
102
|
["Jos(?:eph)*\\.* Smith(?:[–—\\- ]+History)", "Joseph Smith\u2014History"],
|
|
103
|
-
["JS[—\\-]*\\s*[H]", "Joseph Smith
|
|
104
|
-
["JS[—\\-]*\\s*[M]", "Joseph Smith
|
|
103
|
+
["JS[—\\-]*\\s*[H]", "Joseph Smith\u2014History"],
|
|
104
|
+
["JS[—\\-]*\\s*[M]", "Joseph Smith\u2014Matthew"],
|
|
105
105
|
["a(?:rticles)*[ _-]*o[ _-f]*f(?:aith)*", "Articles of Faith"],
|
|
106
106
|
|
|
107
107
|
[",* *jst", "JST"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripture-guide",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
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/scriptures-compiled.js
CHANGED
|
@@ -110,16 +110,25 @@ var lookupReference = function lookupReference(query) {
|
|
|
110
110
|
for (var i in refs) {
|
|
111
111
|
verse_ids = verse_ids.concat(lookupSingleRef(refs[i]));
|
|
112
112
|
}
|
|
113
|
+
if (verse_ids.length == 0 && lang) {
|
|
114
|
+
var original_lang = lang + ""; //clone
|
|
115
|
+
//try again with no language
|
|
116
|
+
setLanguage();
|
|
117
|
+
var results = lookupReference(query);
|
|
118
|
+
setLanguage(original_lang);
|
|
119
|
+
return results;
|
|
120
|
+
}
|
|
113
121
|
return {
|
|
114
122
|
"query": query,
|
|
115
123
|
"ref": ref,
|
|
116
|
-
//"gen": generateReference(verse_ids),
|
|
124
|
+
// "gen": generateReference(verse_ids),
|
|
117
125
|
"verse_ids": verse_ids
|
|
118
126
|
};
|
|
119
127
|
};
|
|
120
128
|
var lookupSingleRef = function lookupSingleRef(ref) {
|
|
129
|
+
var booksWithDashRegex = /^(joseph|조셉)/i; // TODO: get from lang config
|
|
121
130
|
//todo: better handling of multi-book ranges for unicode
|
|
122
|
-
if (ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
|
|
131
|
+
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
|
|
123
132
|
var book = getBook(ref);
|
|
124
133
|
if (!book) return [];
|
|
125
134
|
var ranges = getRanges(ref, book);
|
|
@@ -184,14 +193,14 @@ var strToHash = function strToHash(str) {
|
|
|
184
193
|
//max 32
|
|
185
194
|
if (hash > 2147483647) hash = hash % 2147483647;
|
|
186
195
|
}
|
|
187
|
-
return "
|
|
196
|
+
return "==".concat(hash, "==");
|
|
188
197
|
};
|
|
189
198
|
var cleanReference = function cleanReference(messyReference) {
|
|
190
199
|
var ref = messyReference.replace(/[\s]+/g, " ").trim();
|
|
191
200
|
var hasNoAlpha = !/[A-Za-z]/.test(ref);
|
|
192
201
|
if (hasNoAlpha) wordBreak = "";
|
|
193
202
|
ref = preProcess(ref);
|
|
194
|
-
|
|
203
|
+
var buffer = wordBreak ? "" : " ";
|
|
195
204
|
//Build Regex rules
|
|
196
205
|
var regex = raw_regex.pre_rules;
|
|
197
206
|
for (var i in regex) {
|
|
@@ -199,9 +208,9 @@ var cleanReference = function cleanReference(messyReference) {
|
|
|
199
208
|
ref = ref.replace(re, regex[i][1]);
|
|
200
209
|
}
|
|
201
210
|
var srcbooks = raw_regex.books;
|
|
202
|
-
var dstbooks = raw_regex.books.map(function (i) {
|
|
211
|
+
var dstbooks = buffer ? raw_regex.books.map(function (i) {
|
|
203
212
|
return [i[1], i[1]];
|
|
204
|
-
});
|
|
213
|
+
}) : [];
|
|
205
214
|
var bookMatchList = [].concat(_toConsumableArray(dstbooks), _toConsumableArray(srcbooks)).sort(function (a, b) {
|
|
206
215
|
return b[0].length - a[0].length;
|
|
207
216
|
});
|
|
@@ -213,7 +222,6 @@ var cleanReference = function cleanReference(messyReference) {
|
|
|
213
222
|
var hash = strToHash(book);
|
|
214
223
|
hashCypher[book] = hash;
|
|
215
224
|
}
|
|
216
|
-
var buffer = wordBreak ? "" : " ";
|
|
217
225
|
for (var _i2 in regex) {
|
|
218
226
|
var re = new RegExp(wordBreak + buffer + regex[_i2][0] + buffer + "\\.*" + wordBreak, "ig");
|
|
219
227
|
var replacement = hashCypher[regex[_i2][1]] || regex[_i2][1];
|
|
@@ -250,6 +258,7 @@ var splitReferences = function splitReferences(compoundReference) {
|
|
|
250
258
|
};
|
|
251
259
|
var getBook = function getBook(ref) {
|
|
252
260
|
var book = ref.replace(/([ 0-9:,-]+)$/, '').trim();
|
|
261
|
+
book = book.replace(/-/g, "—");
|
|
253
262
|
if (bookExists(book)) return book;
|
|
254
263
|
return false;
|
|
255
264
|
};
|
package/scriptures.js
CHANGED
|
@@ -78,18 +78,30 @@ const lookupReference = function(query) {
|
|
|
78
78
|
for (let i in refs) {
|
|
79
79
|
verse_ids = verse_ids.concat(lookupSingleRef(refs[i]));
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
if(verse_ids.length == 0 && lang)
|
|
83
|
+
{
|
|
84
|
+
const original_lang = lang+""; //clone
|
|
85
|
+
//try again with no language
|
|
86
|
+
setLanguage();
|
|
87
|
+
const results = lookupReference(query);
|
|
88
|
+
setLanguage(original_lang);
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
return {
|
|
82
93
|
"query": query,
|
|
83
94
|
"ref": ref,
|
|
84
|
-
|
|
95
|
+
// "gen": generateReference(verse_ids),
|
|
85
96
|
"verse_ids": verse_ids
|
|
86
97
|
};
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
const lookupSingleRef = function(ref) {
|
|
90
101
|
|
|
102
|
+
const booksWithDashRegex = /^(joseph|조셉)/i; // TODO: get from lang config
|
|
91
103
|
//todo: better handling of multi-book ranges for unicode
|
|
92
|
-
if (ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
|
|
104
|
+
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
|
|
93
105
|
let book = getBook(ref);
|
|
94
106
|
if (!book) return [];
|
|
95
107
|
let ranges = getRanges(ref, book);
|
|
@@ -162,7 +174,7 @@ const strToHash = function(str) {
|
|
|
162
174
|
//max 32
|
|
163
175
|
if (hash > 2147483647) hash = hash % 2147483647;
|
|
164
176
|
}
|
|
165
|
-
return
|
|
177
|
+
return `==${hash}==`;
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
|
|
@@ -175,7 +187,7 @@ const cleanReference = function(messyReference) {
|
|
|
175
187
|
|
|
176
188
|
ref = preProcess(ref);
|
|
177
189
|
|
|
178
|
-
|
|
190
|
+
const buffer = wordBreak ? "" : " ";
|
|
179
191
|
//Build Regex rules
|
|
180
192
|
let regex = raw_regex.pre_rules;
|
|
181
193
|
for (let i in regex) {
|
|
@@ -183,7 +195,7 @@ const cleanReference = function(messyReference) {
|
|
|
183
195
|
ref = ref.replace(re, regex[i][1]);
|
|
184
196
|
}
|
|
185
197
|
let srcbooks = raw_regex.books;
|
|
186
|
-
let dstbooks = raw_regex.books.map(i => [i[1], i[1]]);
|
|
198
|
+
let dstbooks = buffer ? raw_regex.books.map(i => [i[1], i[1]]) : [];
|
|
187
199
|
let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
|
|
188
200
|
regex = bookMatchList;
|
|
189
201
|
let hashCypher = {};
|
|
@@ -192,7 +204,6 @@ const cleanReference = function(messyReference) {
|
|
|
192
204
|
const hash = strToHash(book);
|
|
193
205
|
hashCypher[book] = hash;
|
|
194
206
|
}
|
|
195
|
-
const buffer = wordBreak ? "" : " ";
|
|
196
207
|
for (let i in regex) {
|
|
197
208
|
var re = new RegExp( wordBreak + buffer + regex[i][0] + buffer + "\\.*"+wordBreak, "ig");
|
|
198
209
|
let replacement = hashCypher[regex[i][1]] || regex[i][1];
|
|
@@ -205,7 +216,6 @@ const cleanReference = function(messyReference) {
|
|
|
205
216
|
return bookValue + " ";
|
|
206
217
|
}
|
|
207
218
|
);
|
|
208
|
-
|
|
209
219
|
regex = raw_regex.post_rules;
|
|
210
220
|
for (let i in regex) {
|
|
211
221
|
var re = new RegExp(regex[i][0], "ig");
|
|
@@ -232,6 +242,7 @@ const splitReferences = function(compoundReference) {
|
|
|
232
242
|
}
|
|
233
243
|
const getBook = function(ref) {
|
|
234
244
|
let book = ref.replace(/([ 0-9:,-]+)$/, '').trim();
|
|
245
|
+
book = book.replace(/-/g, "—");
|
|
235
246
|
if (bookExists(book)) return book;
|
|
236
247
|
return false;
|
|
237
248
|
}
|
package/test-lang.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
const {lookup, generateReference, setLanguage, detectReferences}= require("./scriptures.js");
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
setLanguage("ko");
|
|
5
|
-
console.log(lookup("니파이후서 1장 4절"));
|
|
6
|
-
setLanguage();
|
|
7
|
-
console.log(lookup("Helaman 6:26"));
|
|
3
|
+
|
|
8
4
|
setLanguage("ko");
|
|
9
5
|
//korean tests
|
|
10
6
|
const lookUpTests = [
|
|
11
7
|
"이더서 13장 18절",
|
|
12
8
|
"니전5.2",
|
|
9
|
+
"제3니파이 2장 8절",
|
|
10
|
+
"제3니파이 23장 7절",
|
|
11
|
+
"조셉 스미스—역사 1장 30절",
|
|
12
|
+
"Matthew 4",
|
|
13
|
+
"이더서 1장 32~35절, 이더서 7장 26절, 이더서 9장 23절",
|
|
13
14
|
|
|
14
|
-
]
|
|
15
|
+
];
|
|
15
16
|
|
|
16
17
|
lookUpTests.forEach(t=>{
|
|
17
18
|
const result = lookup(t);
|
|
18
19
|
console.log({result});
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
+
process.exit();
|
|
21
22
|
setLanguage();
|
|
22
|
-
//
|
|
23
|
+
//english tests
|
|
23
24
|
const lookUpTests2 = [
|
|
24
|
-
"
|
|
25
|
+
"Moses 1:1",
|
|
26
|
+
"3 Nephi 9:3",
|
|
27
|
+
"Joseph Smith—History 1:20",
|
|
28
|
+
|
|
25
29
|
]
|
|
26
30
|
|
|
27
31
|
lookUpTests2.forEach(t=>{
|