scripture-guide 1.0.82 → 1.0.83
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/dist/scriptures.cjs +44 -290
- package/dist/scriptures.mjs +44 -290
- package/package.json +1 -1
package/dist/scriptures.cjs
CHANGED
|
@@ -213,8 +213,20 @@ const raw_regex_orig = {
|
|
|
213
213
|
const raw_lang = {
|
|
214
214
|
ko:{
|
|
215
215
|
spacing: ["", " "],
|
|
216
|
-
books:{ "창세기": ["창"], "출애굽기": ["출", "탈출기"], "레위기": ["레"], "민수기": ["민"], "신명기": ["신"], "여호수아": ["수"], "사사기": ["삿", "판관기"], "룻기": ["룻"], "사무엘상": ["삼상"], "사무엘하": ["삼하"], "열왕기상": ["왕상"], "열왕기하": ["왕하"], "역대상": ["대상", "역대기 *상"], "역대하": ["대하", "역대기 *하"], "에스라": ["스", "에즈라"], "느헤미야": ["느"], "에스더": ["에", "에스텔"], "욥기": ["욥"], "시편": ["시"], "잠언": ["잠"], "전도서": ["전", "코헬렛"], "아가": ["아"], "이사야": ["사", "이사야서"], "예레미야": ["렘", "예레미야서"], "예레미야애가": ["애"], "에스겔": ["겔", "에제키엘"], "다니엘": ["단", "다니엘서"], "호세아": ["호", "호세아서"], "요엘": ["욜", "요엘서"], "아모스": ["암", "아모스서"], "오바댜": ["옵", "오바댜서", "오바디야"], "요나": ["욘", "요나서"], "미가": ["미", "미가서"], "나훔": ["나", "나훔서"], "하박국": ["합", "[하합]박[꾹국]서*"], "스바냐": ["습", "스바니야"], "학개": ["학", "하깨"], "스가랴": ["슥", "즈가리야"], "말라기": ["말", "말라기서"], "마태복음": ["마", "마태", "마태오 복음서", "마태오의 복음서"], "마가복음": ["막", "마가", "마르코 복음서"], "누가복음": ["눅","[루누][가카]","[루누][가카] *복음서*"], "요한복음": ["요", "요한", "요한 *복음서*"], "사도행전": ["사*도*행전*","악"], "로마서": ["롬", "로마인들에게 보낸 편지"], "고린도전서": ["고전", "코린토1서"], "고린도후서": ["고후", "코린토2서"], "갈라디아서": ["갈"], "에베소서": ["엡", "에페소인들에게 보낸 편지"], "빌립보서": ["빌", "필리피서"], "골로새서": ["골", "콜로새서"], "데살로니가전서": ["살전", "테살로니카1서"], "데살로니가후서": ["살후", "테살로니카2서"], "디모데전서": ["딤전", "티모테오1서"], "디모데후서": ["딤후", "티모테오2서", "티모테후서"], "디도서": ["딛", "티토서"], "빌레몬서": ["몬", "필레몬서"], "히브리서": ["히"], "야고보서": ["약"], "베드로전서": ["베드로 전서","벧전", "베드로1서"], "베드로후서": ["베드로 후서", "벧후", "베드로2서"], "요한일서": ["요1", "요(일|1)", "(일|1)요"], "요한이서": ["요2", "요(이|2)", "(이|2)요"], "요한삼서": ["요3", "요(삼|3)", "(삼|3)요"], "유다서": ["유다*", "유다의 편지"], "요한 계시록": ["계시*록*", "요한 *[묵계]시록"], "니파이전서": ["니전"], "니파이후서": ["니후"], "야곱서": ["야곱"], "이노스서": ["이노", "이노스서"], "예이롬서": ["예이", "예이롬"], "옴나이서": ["옴", "옴나이"], "몰몬의 말씀": ["몰말", "몰몬말씀"], "모사이야서": ["모사", "모사이야"], "앨마서": ["앨", "앨마"], "힐라맨서": ["힐", "힐라맨"], "제3니파이": ["3니", "제* *3 *니파이서*"], "제4니파이": ["4니", "제* *4 *니파이서*"], "몰몬서": ["몰", "몰몬"], "이더서": ["이더"], "모로나이서": ["모로", "모로나이"],
|
|
216
|
+
books:{ "창세기": ["창"], "출애굽기": ["출", "탈출기"], "레위기": ["레"], "민수기": ["민"], "신명기": ["신"], "여호수아": ["수"], "사사기": ["삿", "판관기"], "룻기": ["룻"], "사무엘상": ["삼상"], "사무엘하": ["삼하"], "열왕기상": ["왕상"], "열왕기하": ["왕하"], "역대상": ["대상", "역대기 *상"], "역대하": ["대하", "역대기 *하"], "에스라": ["스", "에즈라"], "느헤미야": ["느"], "에스더": ["에", "에스텔"], "욥기": ["욥"], "시편": ["시"], "잠언": ["잠"], "전도서": ["전", "코헬렛"], "아가": ["아"], "이사야": ["사", "이사야서"], "예레미야": ["렘", "예레미야서"], "예레미야애가": ["애"], "에스겔": ["겔", "에제키엘"], "다니엘": ["단", "다니엘서"], "호세아": ["호", "호세아서"], "요엘": ["욜", "요엘서"], "아모스": ["암", "아모스서"], "오바댜": ["옵", "오바댜서", "오바디야"], "요나": ["욘", "요나서"], "미가": ["미", "미가서"], "나훔": ["나", "나훔서"], "하박국": ["합", "[하합]박[꾹국]서*"], "스바냐": ["습", "스바니야"], "학개": ["학", "하깨"], "스가랴": ["슥", "즈가리야"], "말라기": ["말", "말라기서"], "마태복음": ["마", "마태", "마태오 복음서", "마태오의 복음서"], "마가복음": ["막", "마가", "마르코 복음서"], "누가복음": ["눅","[루누][가카]","[루누][가카] *복음서*"], "요한복음": ["요", "요한", "요한 *복음서*"], "사도행전": ["사*도*행전*","악"], "로마서": ["롬", "로마인들에게 보낸 편지"], "고린도전서": ["고전", "코린토1서"], "고린도후서": ["고후", "코린토2서"], "갈라디아서": ["갈"], "에베소서": ["엡", "에페소인들에게 보낸 편지"], "빌립보서": ["빌", "필리피서"], "골로새서": ["골", "콜로새서"], "데살로니가전서": ["살전", "테살로니카1서"], "데살로니가후서": ["살후", "테살로니카2서"], "디모데전서": ["딤전", "티모테오1서"], "디모데후서": ["딤후", "티모테오2서", "티모테후서"], "디도서": ["딛", "티토서"], "빌레몬서": ["몬", "필레몬서"], "히브리서": ["히"], "야고보서": ["약"], "베드로전서": ["베드로 전서","벧전", "베드로1서"], "베드로후서": ["베드로 후서", "벧후", "베드로2서"], "요한일서": ["요1", "요(일|1)", "(일|1)요"], "요한이서": ["요2", "요(이|2)", "(이|2)요"], "요한삼서": ["요3", "요(삼|3)", "(삼|3)요"], "유다서": ["유다*", "유다의 편지"], "요한 계시록": ["계시*록*", "요한 *[묵계]시록"], "니파이전서": ["니전"], "니파이후서": ["니후"], "야곱서": ["야곱"], "이노스서": ["이노", "이노스서"], "예이롬서": ["예이", "예이롬"], "옴나이서": ["옴", "옴나이"], "몰몬의 말씀": ["몰말", "몰몬말씀"], "모사이야서": ["모사", "모사이야"], "앨마서": ["앨", "앨마"], "힐라맨서": ["힐", "힐라맨"], "제3니파이": ["3니", "제* *3 *니파이서*"], "제4니파이": ["4니", "제* *4 *니파이서*"], "몰몬서": ["몰", "몰몬"], "이더서": ["이더"], "모로나이서": ["모로", "모로나이"], "교리와 성약": ["교성", "교리성약", "교리와성약"], "모세서": ["모세"], "아브라함서": ["아브", "아브라함"], "조셉 스미스—마태복음": ["조마", "조셉 스미스—마태"], "조셉 스미스—역사": ["조역", "조셉 스미스—역사"], "신앙개조": ["신개"] },
|
|
217
217
|
pre_rules: [
|
|
218
|
+
// Handle 편 (section) suffix - MUST be first to catch all cases
|
|
219
|
+
["교리와\\s*성약\\s*(\\d+)\\s*편", "교리성약 $1"], // "교리와 성약 76편" -> "교리성약 76"
|
|
220
|
+
["교성\\s*(\\d+)\\s*편", "교성 $1"], // "교성 76편" -> "교성 76"
|
|
221
|
+
["(\\d+)\\s*편", "$1"], // General "76편" -> "76"
|
|
222
|
+
|
|
223
|
+
// Handle spaced forms
|
|
224
|
+
["교리와\\s*성약", "교리성약"], // Convert spaced form to non-spaced form
|
|
225
|
+
|
|
226
|
+
// Handle parenthetical verses
|
|
227
|
+
["\\((\\d+~\\d+)절\\)", " $1절"], // Handle "(20~24절)" -> " 20~24절"
|
|
228
|
+
["\\((\\d+)절\\)", " $1절"], // Handle "(20절)" -> " 20절"
|
|
229
|
+
|
|
218
230
|
//handle 1장 2절-3절
|
|
219
231
|
//turn 30 장 10 절 into 30장 10절
|
|
220
232
|
["부터", "-"],
|
|
@@ -245,10 +257,10 @@ const raw_lang = {
|
|
|
245
257
|
],
|
|
246
258
|
matchRules:{
|
|
247
259
|
book: "(제[0-9]+)*",
|
|
248
|
-
chapter:"([
|
|
260
|
+
chapter:"([장절편과와및0-9:;,~\\s—–-]|부터|그리고|또는*)*[0-9장절편]+",
|
|
249
261
|
verse:"절",
|
|
250
262
|
joiners: ["^[;, ]*(또는*|그리고|비교|과|와)*$"],
|
|
251
|
-
tail: "[
|
|
263
|
+
tail: "[^장절편0-9]+$"
|
|
252
264
|
},
|
|
253
265
|
},
|
|
254
266
|
de:{
|
|
@@ -646,288 +658,9 @@ const raw_lang = {
|
|
|
646
658
|
}
|
|
647
659
|
}
|
|
648
660
|
;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
try {
|
|
652
|
-
// For Vietnamese and other languages, handle more flexible matching
|
|
653
|
-
let pattern = book;
|
|
654
|
-
|
|
655
|
-
// Replace * with optional space/separator patterns
|
|
656
|
-
pattern = pattern.replace(/\*/g, '');
|
|
657
|
-
|
|
658
|
-
// Make separators very flexible - handle spaces, hyphens, dots, etc.
|
|
659
|
-
pattern = pattern.replace(/[\s\-–—\.]+/g, '[\\s\\-–—\\.]*');
|
|
660
|
-
|
|
661
|
-
const regex = new RegExp(pattern, "ig");
|
|
662
|
-
const result = regex.test(content);
|
|
663
|
-
|
|
664
|
-
return result;
|
|
665
|
-
} catch (e) {
|
|
666
|
-
// Fallback to original logic if regex fails
|
|
667
|
-
return (new RegExp(book,"ig")).test(content);
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
return matchingBooks;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
const findMatches = (content,books,lang_extra) => {
|
|
674
|
-
// Pre-process content to normalize HTML entities to Unicode dashes
|
|
675
|
-
const htmlEntityMap = {
|
|
676
|
-
'–': '–',
|
|
677
|
-
'—': '—',
|
|
678
|
-
'−': '–', // Treat minus as en dash for scripture ranges
|
|
679
|
-
'–': '–',
|
|
680
|
-
'—': '—',
|
|
681
|
-
'−': '–' // Treat minus as en dash for scripture ranges
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
let normalizedContent = content;
|
|
685
|
-
Object.entries(htmlEntityMap).forEach(([entity, unicode]) => {
|
|
686
|
-
normalizedContent = normalizedContent.replace(new RegExp(entity, 'g'), unicode);
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
|
|
690
|
-
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*`;
|
|
691
|
-
const matchingBooks = findMatchingBooks(normalizedContent,books);
|
|
692
|
-
const postBookMatch = lang_extra.chapter || "([0-9:.;,~ —–-]|cf)*[0-9]+";
|
|
693
|
-
const fullBookMatches = matchingBooks.map(bookMatch=>{
|
|
694
|
-
const patternString = preBookMatch + bookMatch ;
|
|
695
|
-
const pattern = (new RegExp(patternString,"ig"));
|
|
696
|
-
const stringMatch = pattern.test(normalizedContent) ? patternString : null;
|
|
697
|
-
//console.log({pattern,content,stringMatch});
|
|
698
|
-
return stringMatch;
|
|
699
|
-
}).filter(x=>!!x);
|
|
700
|
-
|
|
701
|
-
const bookSubStrings = fullBookMatches.map(bookMatch=>{
|
|
702
|
-
const substrings = normalizedContent.match(new RegExp(bookMatch,"ig")).flat();
|
|
703
|
-
return substrings;
|
|
704
|
-
}).flat().reduce((prev,current)=>{
|
|
705
|
-
if(prev.includes(current)) return prev;
|
|
706
|
-
return [...prev,current]
|
|
707
|
-
},[]).filter(i=>!!i).map(substring=>{
|
|
708
|
-
substring = substring.trim();
|
|
709
|
-
let positions = [];
|
|
710
|
-
let index = normalizedContent.indexOf(substring);
|
|
711
|
-
while (index != -1) {
|
|
712
|
-
positions.push(index);
|
|
713
|
-
index = normalizedContent.indexOf(substring, index + 1);
|
|
714
|
-
} return [substring,positions];
|
|
715
|
-
}).map(([substring,positions])=>{
|
|
716
|
-
const preChars = positions.map(i=>normalizedContent.substring(i-1,i));
|
|
717
|
-
positions = positions.filter((i,index)=>{
|
|
718
|
-
const charRightBeforeMatch = preChars[index];
|
|
719
|
-
const leadingCharIsInvalid = !/^(\s|\W|)$/.test(charRightBeforeMatch);
|
|
720
|
-
return !leadingCharIsInvalid;
|
|
721
|
-
});
|
|
722
|
-
if(!positions.length) return false;
|
|
723
|
-
return [substring,positions];
|
|
724
|
-
}).filter(i=>!!i);
|
|
725
|
-
|
|
726
|
-
const possiblyOverlappingMatches = bookSubStrings.map(([substring,positions])=>{
|
|
727
|
-
return positions.map(i=>{
|
|
728
|
-
let pattern = null;
|
|
729
|
-
try{
|
|
730
|
-
pattern = new RegExp(substring+postBookMatch,"ig");
|
|
731
|
-
}catch(e){
|
|
732
|
-
return null;
|
|
733
|
-
}
|
|
734
|
-
const match = normalizedContent.slice(i).match(pattern)?.[0]?.replace(tail,"").trim();
|
|
735
|
-
if(!match) return null;
|
|
736
|
-
const len = match.length;
|
|
737
|
-
const pos = i;
|
|
738
|
-
const [posIn, posOut] = [pos,pos+len];
|
|
739
|
-
//console.log({content:content.slice(i),pattern,match,posIn,posOut});
|
|
740
|
-
return [match,posIn,posOut];
|
|
741
|
-
}
|
|
742
|
-
)}).flat().filter(i=>!!i);
|
|
743
|
-
const matchesWithReferences = possiblyOverlappingMatches.map(([string,start,end])=>{
|
|
744
|
-
const overLappingItems = possiblyOverlappingMatches.filter(([s,s1,e1])=>s!==string && s1<end && e1>end);
|
|
745
|
-
const hasOverlap = overLappingItems.length > 0;
|
|
746
|
-
const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s,s1,e1])=>s1)) : end;
|
|
747
|
-
const newString = normalizedContent.slice(start,newEnd);
|
|
748
|
-
return newString.replace(tail,"").trim();
|
|
749
|
-
}).filter(i=>!!i);
|
|
750
|
-
const matches = matchesWithReferences.map(string=>{
|
|
751
|
-
const pattern = (new RegExp(string,"ig"));
|
|
752
|
-
const matches = normalizedContent.match(pattern)?.map(i=>i.trim().replace(tail,""));
|
|
753
|
-
//console.log({string,matches,tail});
|
|
754
|
-
return matches;
|
|
755
|
-
}).flat()
|
|
756
|
-
.reduce((prev,current)=>{
|
|
757
|
-
if(prev.includes(current)) return prev;
|
|
758
|
-
return [...prev,current]
|
|
759
|
-
},[]).filter(i=>!!i);
|
|
760
|
-
return {matches, normalizedContent};
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
function findMatchIndexes(content, matches,lookupReference, lang_extra) {
|
|
766
|
-
const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
|
|
767
|
-
const indexes = matches
|
|
768
|
-
.sort((b, a) => b.length - a.length)
|
|
769
|
-
.map(i=>{
|
|
770
|
-
const length = i.length;
|
|
771
|
-
let positions = [];
|
|
772
|
-
let strPos = content.indexOf(i);
|
|
773
|
-
|
|
774
|
-
while (strPos != -1) {
|
|
775
|
-
positions.push(strPos);
|
|
776
|
-
strPos = content.indexOf(i, strPos + 1);
|
|
777
|
-
}
|
|
778
|
-
return positions.map(i=>[i,i+length+2]);
|
|
779
|
-
}).flat()
|
|
780
|
-
.map(a=>{
|
|
781
|
-
|
|
782
|
-
const substring = content.substring(a[0],a[1]).trim().replace(tail,"").trim();
|
|
783
|
-
if(!substring) return false;
|
|
784
|
-
const verse_ids = lookupReference(substring).verse_ids;
|
|
785
|
-
//console.log({substring,verse_ids});
|
|
786
|
-
if(verse_ids.length > 0) return [a[0],a[0]+substring.length];
|
|
787
|
-
|
|
788
|
-
return false;
|
|
789
|
-
})
|
|
790
|
-
.filter(i=>!!i)
|
|
791
|
-
.sort((a, b) => a[0] - b[0])
|
|
792
|
-
.map(([start, end], index, array) => {
|
|
793
|
-
const nextStart = array[index+1]?.[0] || null;
|
|
794
|
-
end = nextStart ? Math.min(end,nextStart) : end;
|
|
795
|
-
return [start,end];
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
if(!indexes.length) return false;
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const tieBreaker = (pair1,pair2)=>{
|
|
802
|
-
const string1 = content.substring(pair1[0],pair1[1]);
|
|
803
|
-
const string2 = content.substring(pair2[0],pair2[1]);
|
|
804
|
-
|
|
805
|
-
// if one pair is all lower case, return the other one
|
|
806
|
-
if(/[^A-Z]/.test(string1) && !/[^A-Z]/.test(string2)) return pair2;
|
|
807
|
-
if(/[^A-Z]/.test(string2) && !/[^A-Z]/.test(string1)) return pair1;
|
|
808
|
-
|
|
809
|
-
if(string1.length > string2.length) return pair1;
|
|
810
|
-
if(string2.length > string1.length) return pair2;
|
|
811
|
-
|
|
812
|
-
return pair1;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const nonOverlappingIndeces = indexes.reduce((prev, current) => {
|
|
817
|
-
if (prev.length === 0) {
|
|
818
|
-
return [current];
|
|
819
|
-
}
|
|
820
|
-
const lastPair = prev[prev.length - 1];
|
|
821
|
-
if (current[0] < lastPair[1]) { // They overlap
|
|
822
|
-
const chosenPair = tieBreaker(lastPair, current);
|
|
823
|
-
if (chosenPair === lastPair) {
|
|
824
|
-
// Keep the last pair, discard the current one
|
|
825
|
-
return prev;
|
|
826
|
-
} else {
|
|
827
|
-
// Replace the last pair with the current one
|
|
828
|
-
prev.pop();
|
|
829
|
-
return [...prev, current];
|
|
830
|
-
}
|
|
831
|
-
} else {
|
|
832
|
-
// They don't overlap, add the current pair
|
|
833
|
-
return [...prev, current];
|
|
834
|
-
}
|
|
835
|
-
}, []).filter(([start,end])=>start!==end);
|
|
661
|
+
import { processReferenceDetection } from './scriptdetect.mjs';
|
|
662
|
+
import { detectReferencesWithContext } from './scriptdetectcontext.mjs';
|
|
836
663
|
|
|
837
|
-
|
|
838
|
-
return nonOverlappingIndeces;
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
const processReferenceDetection = (content,books,lang_extra,lookupReference,callback) =>
|
|
849
|
-
{
|
|
850
|
-
try{
|
|
851
|
-
lang_extra = lang_extra || {};
|
|
852
|
-
const {matches, normalizedContent} = findMatches(content,books,lang_extra);
|
|
853
|
-
const matchIndeces = findMatchIndexes(normalizedContent,matches,lookupReference,lang_extra);
|
|
854
|
-
if(!matchIndeces) return content;
|
|
855
|
-
const gapsBetweenIndeces = matchIndeces.reduce((prev,current,index)=>{
|
|
856
|
-
if(index === 0) return prev;
|
|
857
|
-
const lastPair = matchIndeces[index-1];
|
|
858
|
-
const gap = [lastPair[1],current[0]];
|
|
859
|
-
return [...prev,gap];
|
|
860
|
-
},[]);
|
|
861
|
-
const gapStrings = gapsBetweenIndeces.map(([start,end])=>normalizedContent.substring(start,end).trim());
|
|
862
|
-
//console.log({matches,matchIndeces,gapsBetweenIndeces,gapStrings});
|
|
863
|
-
const joiners = lang_extra.joiners || ["^[;, ]*(and|c\\.*f\\.*)*$"];
|
|
864
|
-
const gapThatMayBeMerged = gapsBetweenIndeces.map(([start,end],i)=>{
|
|
865
|
-
const gapString = gapStrings[i];
|
|
866
|
-
const canBeMerged = joiners.some(joiner=>(new RegExp(joiner,"ig")).test(gapString));
|
|
867
|
-
const matchingJoiner = joiners.find(joiner=>(new RegExp(joiner,"ig")).test(gapString));
|
|
868
|
-
//console.log({gapString,matchingJoiner});
|
|
869
|
-
return canBeMerged;
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
// new incexes
|
|
874
|
-
const mergedIndeces = matchIndeces.reduce((prev, current, index) => {
|
|
875
|
-
if (index === 0) {
|
|
876
|
-
return [current];
|
|
877
|
-
} else {
|
|
878
|
-
const prevIndex = prev[prev.length - 1];
|
|
879
|
-
if (gapThatMayBeMerged[index - 1]) {
|
|
880
|
-
const merged = [prevIndex[0], current[1]];
|
|
881
|
-
prev[prev.length - 1] = merged;
|
|
882
|
-
} else {
|
|
883
|
-
prev.push(current);
|
|
884
|
-
}
|
|
885
|
-
return prev;
|
|
886
|
-
}
|
|
887
|
-
}, []);
|
|
888
|
-
|
|
889
|
-
//get the gaps and the front/end bumpers if any
|
|
890
|
-
const negativeSpace = mergedIndeces.reduce((prev, current, index, array) => {
|
|
891
|
-
if (index !== 0) {
|
|
892
|
-
const prevIndex = array[index - 1];
|
|
893
|
-
const gap = [prevIndex[1], current[0]];
|
|
894
|
-
prev.push(gap);
|
|
895
|
-
}
|
|
896
|
-
return prev;
|
|
897
|
-
}, []);
|
|
898
|
-
|
|
899
|
-
if (mergedIndeces[0][0] !== 0) {
|
|
900
|
-
negativeSpace.unshift([0, mergedIndeces[0][0]]);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (mergedIndeces[mergedIndeces.length - 1][1] !== content.length) {
|
|
904
|
-
negativeSpace.push([mergedIndeces[mergedIndeces.length - 1][1], content.length]);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
//check content between matches. If puctuation only (or 'and'), then merge
|
|
909
|
-
const cutItems = mergedIndeces.map(([start,end])=>{
|
|
910
|
-
const string = normalizedContent.substring(start,end);
|
|
911
|
-
return lookupReference(string).query
|
|
912
|
-
}).map(callback);
|
|
913
|
-
|
|
914
|
-
const negativeItems = negativeSpace.map(([start,end])=>normalizedContent.substring(start,end));
|
|
915
|
-
const firstReferenceIsAtStart = mergedIndeces[0][0] === 0;
|
|
916
|
-
const maxCount = Math.max(cutItems.length,negativeItems.length);
|
|
917
|
-
//merge by alternating cutItems and negativeItems. run the callback on the cut items
|
|
918
|
-
const merged = [];
|
|
919
|
-
for(let i=0;i<maxCount;i++){
|
|
920
|
-
const firstItem = firstReferenceIsAtStart ? cutItems[i] : negativeItems[i];
|
|
921
|
-
const secondItem = firstReferenceIsAtStart ? negativeItems[i] : cutItems[i];
|
|
922
|
-
if(firstItem) merged.push(firstItem);
|
|
923
|
-
if(secondItem) merged.push(secondItem);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
return merged.join("");
|
|
927
|
-
}catch(e){
|
|
928
|
-
return content;
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
664
|
// Browser localStorage key for language preference
|
|
932
665
|
const LANGUAGE_STORAGE_KEY = 'scriptureGuideUtils_language';
|
|
933
666
|
|
|
@@ -1494,18 +1227,39 @@ const loadMaxVerse = function(book, chapter, config) {
|
|
|
1494
1227
|
return config.raw_index[book][parseInt(chapter) - 1]
|
|
1495
1228
|
}
|
|
1496
1229
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1230
|
+
const detectReferences = (content, callBack, options = null) => {
|
|
1231
|
+
// Handle legacy API: (content, callback, language)
|
|
1232
|
+
if (typeof options === 'string' || options === null) {
|
|
1233
|
+
const language = options;
|
|
1234
|
+
options = { language };
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// Default options
|
|
1238
|
+
const defaultOptions = {
|
|
1239
|
+
language: null,
|
|
1240
|
+
contextAware: true,
|
|
1241
|
+
contextScope: 'sentence',
|
|
1242
|
+
maxContextDistance: 500,
|
|
1243
|
+
enableImpliedBooks: true,
|
|
1244
|
+
enableVerseAbbrev: true
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
const finalOptions = { ...defaultOptions, ...options };
|
|
1501
1248
|
callBack = callBack ? callBack : (i)=>{return `[${i}]`};
|
|
1502
|
-
|
|
1249
|
+
|
|
1250
|
+
const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
|
|
1503
1251
|
const config = getLanguageConfig(effectiveLanguage);
|
|
1504
1252
|
const src = config.raw_regex.books.map(i => i[0]);
|
|
1505
1253
|
const dst = [...new Set(config.raw_regex.books.map(i => i[1]))];
|
|
1506
1254
|
const books = [...dst, ...src];
|
|
1255
|
+
|
|
1256
|
+
// Use enhanced processing if context-aware mode is enabled
|
|
1257
|
+
if (finalOptions.contextAware) {
|
|
1258
|
+
return detectReferencesWithContext(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// Fallback to original processing
|
|
1507
1262
|
return processReferenceDetection(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack);
|
|
1508
|
-
|
|
1509
1263
|
}
|
|
1510
1264
|
|
|
1511
1265
|
const getLanguageConfig = function(language) {
|
package/dist/scriptures.mjs
CHANGED
|
@@ -213,8 +213,20 @@ const raw_regex_orig = {
|
|
|
213
213
|
const raw_lang = {
|
|
214
214
|
ko:{
|
|
215
215
|
spacing: ["", " "],
|
|
216
|
-
books:{ "창세기": ["창"], "출애굽기": ["출", "탈출기"], "레위기": ["레"], "민수기": ["민"], "신명기": ["신"], "여호수아": ["수"], "사사기": ["삿", "판관기"], "룻기": ["룻"], "사무엘상": ["삼상"], "사무엘하": ["삼하"], "열왕기상": ["왕상"], "열왕기하": ["왕하"], "역대상": ["대상", "역대기 *상"], "역대하": ["대하", "역대기 *하"], "에스라": ["스", "에즈라"], "느헤미야": ["느"], "에스더": ["에", "에스텔"], "욥기": ["욥"], "시편": ["시"], "잠언": ["잠"], "전도서": ["전", "코헬렛"], "아가": ["아"], "이사야": ["사", "이사야서"], "예레미야": ["렘", "예레미야서"], "예레미야애가": ["애"], "에스겔": ["겔", "에제키엘"], "다니엘": ["단", "다니엘서"], "호세아": ["호", "호세아서"], "요엘": ["욜", "요엘서"], "아모스": ["암", "아모스서"], "오바댜": ["옵", "오바댜서", "오바디야"], "요나": ["욘", "요나서"], "미가": ["미", "미가서"], "나훔": ["나", "나훔서"], "하박국": ["합", "[하합]박[꾹국]서*"], "스바냐": ["습", "스바니야"], "학개": ["학", "하깨"], "스가랴": ["슥", "즈가리야"], "말라기": ["말", "말라기서"], "마태복음": ["마", "마태", "마태오 복음서", "마태오의 복음서"], "마가복음": ["막", "마가", "마르코 복음서"], "누가복음": ["눅","[루누][가카]","[루누][가카] *복음서*"], "요한복음": ["요", "요한", "요한 *복음서*"], "사도행전": ["사*도*행전*","악"], "로마서": ["롬", "로마인들에게 보낸 편지"], "고린도전서": ["고전", "코린토1서"], "고린도후서": ["고후", "코린토2서"], "갈라디아서": ["갈"], "에베소서": ["엡", "에페소인들에게 보낸 편지"], "빌립보서": ["빌", "필리피서"], "골로새서": ["골", "콜로새서"], "데살로니가전서": ["살전", "테살로니카1서"], "데살로니가후서": ["살후", "테살로니카2서"], "디모데전서": ["딤전", "티모테오1서"], "디모데후서": ["딤후", "티모테오2서", "티모테후서"], "디도서": ["딛", "티토서"], "빌레몬서": ["몬", "필레몬서"], "히브리서": ["히"], "야고보서": ["약"], "베드로전서": ["베드로 전서","벧전", "베드로1서"], "베드로후서": ["베드로 후서", "벧후", "베드로2서"], "요한일서": ["요1", "요(일|1)", "(일|1)요"], "요한이서": ["요2", "요(이|2)", "(이|2)요"], "요한삼서": ["요3", "요(삼|3)", "(삼|3)요"], "유다서": ["유다*", "유다의 편지"], "요한 계시록": ["계시*록*", "요한 *[묵계]시록"], "니파이전서": ["니전"], "니파이후서": ["니후"], "야곱서": ["야곱"], "이노스서": ["이노", "이노스서"], "예이롬서": ["예이", "예이롬"], "옴나이서": ["옴", "옴나이"], "몰몬의 말씀": ["몰말", "몰몬말씀"], "모사이야서": ["모사", "모사이야"], "앨마서": ["앨", "앨마"], "힐라맨서": ["힐", "힐라맨"], "제3니파이": ["3니", "제* *3 *니파이서*"], "제4니파이": ["4니", "제* *4 *니파이서*"], "몰몬서": ["몰", "몰몬"], "이더서": ["이더"], "모로나이서": ["모로", "모로나이"],
|
|
216
|
+
books:{ "창세기": ["창"], "출애굽기": ["출", "탈출기"], "레위기": ["레"], "민수기": ["민"], "신명기": ["신"], "여호수아": ["수"], "사사기": ["삿", "판관기"], "룻기": ["룻"], "사무엘상": ["삼상"], "사무엘하": ["삼하"], "열왕기상": ["왕상"], "열왕기하": ["왕하"], "역대상": ["대상", "역대기 *상"], "역대하": ["대하", "역대기 *하"], "에스라": ["스", "에즈라"], "느헤미야": ["느"], "에스더": ["에", "에스텔"], "욥기": ["욥"], "시편": ["시"], "잠언": ["잠"], "전도서": ["전", "코헬렛"], "아가": ["아"], "이사야": ["사", "이사야서"], "예레미야": ["렘", "예레미야서"], "예레미야애가": ["애"], "에스겔": ["겔", "에제키엘"], "다니엘": ["단", "다니엘서"], "호세아": ["호", "호세아서"], "요엘": ["욜", "요엘서"], "아모스": ["암", "아모스서"], "오바댜": ["옵", "오바댜서", "오바디야"], "요나": ["욘", "요나서"], "미가": ["미", "미가서"], "나훔": ["나", "나훔서"], "하박국": ["합", "[하합]박[꾹국]서*"], "스바냐": ["습", "스바니야"], "학개": ["학", "하깨"], "스가랴": ["슥", "즈가리야"], "말라기": ["말", "말라기서"], "마태복음": ["마", "마태", "마태오 복음서", "마태오의 복음서"], "마가복음": ["막", "마가", "마르코 복음서"], "누가복음": ["눅","[루누][가카]","[루누][가카] *복음서*"], "요한복음": ["요", "요한", "요한 *복음서*"], "사도행전": ["사*도*행전*","악"], "로마서": ["롬", "로마인들에게 보낸 편지"], "고린도전서": ["고전", "코린토1서"], "고린도후서": ["고후", "코린토2서"], "갈라디아서": ["갈"], "에베소서": ["엡", "에페소인들에게 보낸 편지"], "빌립보서": ["빌", "필리피서"], "골로새서": ["골", "콜로새서"], "데살로니가전서": ["살전", "테살로니카1서"], "데살로니가후서": ["살후", "테살로니카2서"], "디모데전서": ["딤전", "티모테오1서"], "디모데후서": ["딤후", "티모테오2서", "티모테후서"], "디도서": ["딛", "티토서"], "빌레몬서": ["몬", "필레몬서"], "히브리서": ["히"], "야고보서": ["약"], "베드로전서": ["베드로 전서","벧전", "베드로1서"], "베드로후서": ["베드로 후서", "벧후", "베드로2서"], "요한일서": ["요1", "요(일|1)", "(일|1)요"], "요한이서": ["요2", "요(이|2)", "(이|2)요"], "요한삼서": ["요3", "요(삼|3)", "(삼|3)요"], "유다서": ["유다*", "유다의 편지"], "요한 계시록": ["계시*록*", "요한 *[묵계]시록"], "니파이전서": ["니전"], "니파이후서": ["니후"], "야곱서": ["야곱"], "이노스서": ["이노", "이노스서"], "예이롬서": ["예이", "예이롬"], "옴나이서": ["옴", "옴나이"], "몰몬의 말씀": ["몰말", "몰몬말씀"], "모사이야서": ["모사", "모사이야"], "앨마서": ["앨", "앨마"], "힐라맨서": ["힐", "힐라맨"], "제3니파이": ["3니", "제* *3 *니파이서*"], "제4니파이": ["4니", "제* *4 *니파이서*"], "몰몬서": ["몰", "몰몬"], "이더서": ["이더"], "모로나이서": ["모로", "모로나이"], "교리와 성약": ["교성", "교리성약", "교리와성약"], "모세서": ["모세"], "아브라함서": ["아브", "아브라함"], "조셉 스미스—마태복음": ["조마", "조셉 스미스—마태"], "조셉 스미스—역사": ["조역", "조셉 스미스—역사"], "신앙개조": ["신개"] },
|
|
217
217
|
pre_rules: [
|
|
218
|
+
// Handle 편 (section) suffix - MUST be first to catch all cases
|
|
219
|
+
["교리와\\s*성약\\s*(\\d+)\\s*편", "교리성약 $1"], // "교리와 성약 76편" -> "교리성약 76"
|
|
220
|
+
["교성\\s*(\\d+)\\s*편", "교성 $1"], // "교성 76편" -> "교성 76"
|
|
221
|
+
["(\\d+)\\s*편", "$1"], // General "76편" -> "76"
|
|
222
|
+
|
|
223
|
+
// Handle spaced forms
|
|
224
|
+
["교리와\\s*성약", "교리성약"], // Convert spaced form to non-spaced form
|
|
225
|
+
|
|
226
|
+
// Handle parenthetical verses
|
|
227
|
+
["\\((\\d+~\\d+)절\\)", " $1절"], // Handle "(20~24절)" -> " 20~24절"
|
|
228
|
+
["\\((\\d+)절\\)", " $1절"], // Handle "(20절)" -> " 20절"
|
|
229
|
+
|
|
218
230
|
//handle 1장 2절-3절
|
|
219
231
|
//turn 30 장 10 절 into 30장 10절
|
|
220
232
|
["부터", "-"],
|
|
@@ -245,10 +257,10 @@ const raw_lang = {
|
|
|
245
257
|
],
|
|
246
258
|
matchRules:{
|
|
247
259
|
book: "(제[0-9]+)*",
|
|
248
|
-
chapter:"([
|
|
260
|
+
chapter:"([장절편과와및0-9:;,~\\s—–-]|부터|그리고|또는*)*[0-9장절편]+",
|
|
249
261
|
verse:"절",
|
|
250
262
|
joiners: ["^[;, ]*(또는*|그리고|비교|과|와)*$"],
|
|
251
|
-
tail: "[
|
|
263
|
+
tail: "[^장절편0-9]+$"
|
|
252
264
|
},
|
|
253
265
|
},
|
|
254
266
|
de:{
|
|
@@ -646,288 +658,9 @@ const raw_lang = {
|
|
|
646
658
|
}
|
|
647
659
|
}
|
|
648
660
|
;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
try {
|
|
652
|
-
// For Vietnamese and other languages, handle more flexible matching
|
|
653
|
-
let pattern = book;
|
|
654
|
-
|
|
655
|
-
// Replace * with optional space/separator patterns
|
|
656
|
-
pattern = pattern.replace(/\*/g, '');
|
|
657
|
-
|
|
658
|
-
// Make separators very flexible - handle spaces, hyphens, dots, etc.
|
|
659
|
-
pattern = pattern.replace(/[\s\-–—\.]+/g, '[\\s\\-–—\\.]*');
|
|
660
|
-
|
|
661
|
-
const regex = new RegExp(pattern, "ig");
|
|
662
|
-
const result = regex.test(content);
|
|
663
|
-
|
|
664
|
-
return result;
|
|
665
|
-
} catch (e) {
|
|
666
|
-
// Fallback to original logic if regex fails
|
|
667
|
-
return (new RegExp(book,"ig")).test(content);
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
return matchingBooks;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
const findMatches = (content,books,lang_extra) => {
|
|
674
|
-
// Pre-process content to normalize HTML entities to Unicode dashes
|
|
675
|
-
const htmlEntityMap = {
|
|
676
|
-
'–': '–',
|
|
677
|
-
'—': '—',
|
|
678
|
-
'−': '–', // Treat minus as en dash for scripture ranges
|
|
679
|
-
'–': '–',
|
|
680
|
-
'—': '—',
|
|
681
|
-
'−': '–' // Treat minus as en dash for scripture ranges
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
let normalizedContent = content;
|
|
685
|
-
Object.entries(htmlEntityMap).forEach(([entity, unicode]) => {
|
|
686
|
-
normalizedContent = normalizedContent.replace(new RegExp(entity, 'g'), unicode);
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
|
|
690
|
-
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*`;
|
|
691
|
-
const matchingBooks = findMatchingBooks(normalizedContent,books);
|
|
692
|
-
const postBookMatch = lang_extra.chapter || "([0-9:.;,~ —–-]|cf)*[0-9]+";
|
|
693
|
-
const fullBookMatches = matchingBooks.map(bookMatch=>{
|
|
694
|
-
const patternString = preBookMatch + bookMatch ;
|
|
695
|
-
const pattern = (new RegExp(patternString,"ig"));
|
|
696
|
-
const stringMatch = pattern.test(normalizedContent) ? patternString : null;
|
|
697
|
-
//console.log({pattern,content,stringMatch});
|
|
698
|
-
return stringMatch;
|
|
699
|
-
}).filter(x=>!!x);
|
|
700
|
-
|
|
701
|
-
const bookSubStrings = fullBookMatches.map(bookMatch=>{
|
|
702
|
-
const substrings = normalizedContent.match(new RegExp(bookMatch,"ig")).flat();
|
|
703
|
-
return substrings;
|
|
704
|
-
}).flat().reduce((prev,current)=>{
|
|
705
|
-
if(prev.includes(current)) return prev;
|
|
706
|
-
return [...prev,current]
|
|
707
|
-
},[]).filter(i=>!!i).map(substring=>{
|
|
708
|
-
substring = substring.trim();
|
|
709
|
-
let positions = [];
|
|
710
|
-
let index = normalizedContent.indexOf(substring);
|
|
711
|
-
while (index != -1) {
|
|
712
|
-
positions.push(index);
|
|
713
|
-
index = normalizedContent.indexOf(substring, index + 1);
|
|
714
|
-
} return [substring,positions];
|
|
715
|
-
}).map(([substring,positions])=>{
|
|
716
|
-
const preChars = positions.map(i=>normalizedContent.substring(i-1,i));
|
|
717
|
-
positions = positions.filter((i,index)=>{
|
|
718
|
-
const charRightBeforeMatch = preChars[index];
|
|
719
|
-
const leadingCharIsInvalid = !/^(\s|\W|)$/.test(charRightBeforeMatch);
|
|
720
|
-
return !leadingCharIsInvalid;
|
|
721
|
-
});
|
|
722
|
-
if(!positions.length) return false;
|
|
723
|
-
return [substring,positions];
|
|
724
|
-
}).filter(i=>!!i);
|
|
725
|
-
|
|
726
|
-
const possiblyOverlappingMatches = bookSubStrings.map(([substring,positions])=>{
|
|
727
|
-
return positions.map(i=>{
|
|
728
|
-
let pattern = null;
|
|
729
|
-
try{
|
|
730
|
-
pattern = new RegExp(substring+postBookMatch,"ig");
|
|
731
|
-
}catch(e){
|
|
732
|
-
return null;
|
|
733
|
-
}
|
|
734
|
-
const match = normalizedContent.slice(i).match(pattern)?.[0]?.replace(tail,"").trim();
|
|
735
|
-
if(!match) return null;
|
|
736
|
-
const len = match.length;
|
|
737
|
-
const pos = i;
|
|
738
|
-
const [posIn, posOut] = [pos,pos+len];
|
|
739
|
-
//console.log({content:content.slice(i),pattern,match,posIn,posOut});
|
|
740
|
-
return [match,posIn,posOut];
|
|
741
|
-
}
|
|
742
|
-
)}).flat().filter(i=>!!i);
|
|
743
|
-
const matchesWithReferences = possiblyOverlappingMatches.map(([string,start,end])=>{
|
|
744
|
-
const overLappingItems = possiblyOverlappingMatches.filter(([s,s1,e1])=>s!==string && s1<end && e1>end);
|
|
745
|
-
const hasOverlap = overLappingItems.length > 0;
|
|
746
|
-
const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s,s1,e1])=>s1)) : end;
|
|
747
|
-
const newString = normalizedContent.slice(start,newEnd);
|
|
748
|
-
return newString.replace(tail,"").trim();
|
|
749
|
-
}).filter(i=>!!i);
|
|
750
|
-
const matches = matchesWithReferences.map(string=>{
|
|
751
|
-
const pattern = (new RegExp(string,"ig"));
|
|
752
|
-
const matches = normalizedContent.match(pattern)?.map(i=>i.trim().replace(tail,""));
|
|
753
|
-
//console.log({string,matches,tail});
|
|
754
|
-
return matches;
|
|
755
|
-
}).flat()
|
|
756
|
-
.reduce((prev,current)=>{
|
|
757
|
-
if(prev.includes(current)) return prev;
|
|
758
|
-
return [...prev,current]
|
|
759
|
-
},[]).filter(i=>!!i);
|
|
760
|
-
return {matches, normalizedContent};
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
function findMatchIndexes(content, matches,lookupReference, lang_extra) {
|
|
766
|
-
const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
|
|
767
|
-
const indexes = matches
|
|
768
|
-
.sort((b, a) => b.length - a.length)
|
|
769
|
-
.map(i=>{
|
|
770
|
-
const length = i.length;
|
|
771
|
-
let positions = [];
|
|
772
|
-
let strPos = content.indexOf(i);
|
|
773
|
-
|
|
774
|
-
while (strPos != -1) {
|
|
775
|
-
positions.push(strPos);
|
|
776
|
-
strPos = content.indexOf(i, strPos + 1);
|
|
777
|
-
}
|
|
778
|
-
return positions.map(i=>[i,i+length+2]);
|
|
779
|
-
}).flat()
|
|
780
|
-
.map(a=>{
|
|
781
|
-
|
|
782
|
-
const substring = content.substring(a[0],a[1]).trim().replace(tail,"").trim();
|
|
783
|
-
if(!substring) return false;
|
|
784
|
-
const verse_ids = lookupReference(substring).verse_ids;
|
|
785
|
-
//console.log({substring,verse_ids});
|
|
786
|
-
if(verse_ids.length > 0) return [a[0],a[0]+substring.length];
|
|
787
|
-
|
|
788
|
-
return false;
|
|
789
|
-
})
|
|
790
|
-
.filter(i=>!!i)
|
|
791
|
-
.sort((a, b) => a[0] - b[0])
|
|
792
|
-
.map(([start, end], index, array) => {
|
|
793
|
-
const nextStart = array[index+1]?.[0] || null;
|
|
794
|
-
end = nextStart ? Math.min(end,nextStart) : end;
|
|
795
|
-
return [start,end];
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
if(!indexes.length) return false;
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const tieBreaker = (pair1,pair2)=>{
|
|
802
|
-
const string1 = content.substring(pair1[0],pair1[1]);
|
|
803
|
-
const string2 = content.substring(pair2[0],pair2[1]);
|
|
804
|
-
|
|
805
|
-
// if one pair is all lower case, return the other one
|
|
806
|
-
if(/[^A-Z]/.test(string1) && !/[^A-Z]/.test(string2)) return pair2;
|
|
807
|
-
if(/[^A-Z]/.test(string2) && !/[^A-Z]/.test(string1)) return pair1;
|
|
808
|
-
|
|
809
|
-
if(string1.length > string2.length) return pair1;
|
|
810
|
-
if(string2.length > string1.length) return pair2;
|
|
811
|
-
|
|
812
|
-
return pair1;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const nonOverlappingIndeces = indexes.reduce((prev, current) => {
|
|
817
|
-
if (prev.length === 0) {
|
|
818
|
-
return [current];
|
|
819
|
-
}
|
|
820
|
-
const lastPair = prev[prev.length - 1];
|
|
821
|
-
if (current[0] < lastPair[1]) { // They overlap
|
|
822
|
-
const chosenPair = tieBreaker(lastPair, current);
|
|
823
|
-
if (chosenPair === lastPair) {
|
|
824
|
-
// Keep the last pair, discard the current one
|
|
825
|
-
return prev;
|
|
826
|
-
} else {
|
|
827
|
-
// Replace the last pair with the current one
|
|
828
|
-
prev.pop();
|
|
829
|
-
return [...prev, current];
|
|
830
|
-
}
|
|
831
|
-
} else {
|
|
832
|
-
// They don't overlap, add the current pair
|
|
833
|
-
return [...prev, current];
|
|
834
|
-
}
|
|
835
|
-
}, []).filter(([start,end])=>start!==end);
|
|
661
|
+
import { processReferenceDetection } from './scriptdetect.mjs';
|
|
662
|
+
import { detectReferencesWithContext } from './scriptdetectcontext.mjs';
|
|
836
663
|
|
|
837
|
-
|
|
838
|
-
return nonOverlappingIndeces;
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
const processReferenceDetection = (content,books,lang_extra,lookupReference,callback) =>
|
|
849
|
-
{
|
|
850
|
-
try{
|
|
851
|
-
lang_extra = lang_extra || {};
|
|
852
|
-
const {matches, normalizedContent} = findMatches(content,books,lang_extra);
|
|
853
|
-
const matchIndeces = findMatchIndexes(normalizedContent,matches,lookupReference,lang_extra);
|
|
854
|
-
if(!matchIndeces) return content;
|
|
855
|
-
const gapsBetweenIndeces = matchIndeces.reduce((prev,current,index)=>{
|
|
856
|
-
if(index === 0) return prev;
|
|
857
|
-
const lastPair = matchIndeces[index-1];
|
|
858
|
-
const gap = [lastPair[1],current[0]];
|
|
859
|
-
return [...prev,gap];
|
|
860
|
-
},[]);
|
|
861
|
-
const gapStrings = gapsBetweenIndeces.map(([start,end])=>normalizedContent.substring(start,end).trim());
|
|
862
|
-
//console.log({matches,matchIndeces,gapsBetweenIndeces,gapStrings});
|
|
863
|
-
const joiners = lang_extra.joiners || ["^[;, ]*(and|c\\.*f\\.*)*$"];
|
|
864
|
-
const gapThatMayBeMerged = gapsBetweenIndeces.map(([start,end],i)=>{
|
|
865
|
-
const gapString = gapStrings[i];
|
|
866
|
-
const canBeMerged = joiners.some(joiner=>(new RegExp(joiner,"ig")).test(gapString));
|
|
867
|
-
const matchingJoiner = joiners.find(joiner=>(new RegExp(joiner,"ig")).test(gapString));
|
|
868
|
-
//console.log({gapString,matchingJoiner});
|
|
869
|
-
return canBeMerged;
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
// new incexes
|
|
874
|
-
const mergedIndeces = matchIndeces.reduce((prev, current, index) => {
|
|
875
|
-
if (index === 0) {
|
|
876
|
-
return [current];
|
|
877
|
-
} else {
|
|
878
|
-
const prevIndex = prev[prev.length - 1];
|
|
879
|
-
if (gapThatMayBeMerged[index - 1]) {
|
|
880
|
-
const merged = [prevIndex[0], current[1]];
|
|
881
|
-
prev[prev.length - 1] = merged;
|
|
882
|
-
} else {
|
|
883
|
-
prev.push(current);
|
|
884
|
-
}
|
|
885
|
-
return prev;
|
|
886
|
-
}
|
|
887
|
-
}, []);
|
|
888
|
-
|
|
889
|
-
//get the gaps and the front/end bumpers if any
|
|
890
|
-
const negativeSpace = mergedIndeces.reduce((prev, current, index, array) => {
|
|
891
|
-
if (index !== 0) {
|
|
892
|
-
const prevIndex = array[index - 1];
|
|
893
|
-
const gap = [prevIndex[1], current[0]];
|
|
894
|
-
prev.push(gap);
|
|
895
|
-
}
|
|
896
|
-
return prev;
|
|
897
|
-
}, []);
|
|
898
|
-
|
|
899
|
-
if (mergedIndeces[0][0] !== 0) {
|
|
900
|
-
negativeSpace.unshift([0, mergedIndeces[0][0]]);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (mergedIndeces[mergedIndeces.length - 1][1] !== content.length) {
|
|
904
|
-
negativeSpace.push([mergedIndeces[mergedIndeces.length - 1][1], content.length]);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
//check content between matches. If puctuation only (or 'and'), then merge
|
|
909
|
-
const cutItems = mergedIndeces.map(([start,end])=>{
|
|
910
|
-
const string = normalizedContent.substring(start,end);
|
|
911
|
-
return lookupReference(string).query
|
|
912
|
-
}).map(callback);
|
|
913
|
-
|
|
914
|
-
const negativeItems = negativeSpace.map(([start,end])=>normalizedContent.substring(start,end));
|
|
915
|
-
const firstReferenceIsAtStart = mergedIndeces[0][0] === 0;
|
|
916
|
-
const maxCount = Math.max(cutItems.length,negativeItems.length);
|
|
917
|
-
//merge by alternating cutItems and negativeItems. run the callback on the cut items
|
|
918
|
-
const merged = [];
|
|
919
|
-
for(let i=0;i<maxCount;i++){
|
|
920
|
-
const firstItem = firstReferenceIsAtStart ? cutItems[i] : negativeItems[i];
|
|
921
|
-
const secondItem = firstReferenceIsAtStart ? negativeItems[i] : cutItems[i];
|
|
922
|
-
if(firstItem) merged.push(firstItem);
|
|
923
|
-
if(secondItem) merged.push(secondItem);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
return merged.join("");
|
|
927
|
-
}catch(e){
|
|
928
|
-
return content;
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
664
|
// Browser localStorage key for language preference
|
|
932
665
|
const LANGUAGE_STORAGE_KEY = 'scriptureGuideUtils_language';
|
|
933
666
|
|
|
@@ -1494,18 +1227,39 @@ const loadMaxVerse = function(book, chapter, config) {
|
|
|
1494
1227
|
return config.raw_index[book][parseInt(chapter) - 1]
|
|
1495
1228
|
}
|
|
1496
1229
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1230
|
+
const detectReferences = (content, callBack, options = null) => {
|
|
1231
|
+
// Handle legacy API: (content, callback, language)
|
|
1232
|
+
if (typeof options === 'string' || options === null) {
|
|
1233
|
+
const language = options;
|
|
1234
|
+
options = { language };
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// Default options
|
|
1238
|
+
const defaultOptions = {
|
|
1239
|
+
language: null,
|
|
1240
|
+
contextAware: true,
|
|
1241
|
+
contextScope: 'sentence',
|
|
1242
|
+
maxContextDistance: 500,
|
|
1243
|
+
enableImpliedBooks: true,
|
|
1244
|
+
enableVerseAbbrev: true
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
const finalOptions = { ...defaultOptions, ...options };
|
|
1501
1248
|
callBack = callBack ? callBack : (i)=>{return `[${i}]`};
|
|
1502
|
-
|
|
1249
|
+
|
|
1250
|
+
const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
|
|
1503
1251
|
const config = getLanguageConfig(effectiveLanguage);
|
|
1504
1252
|
const src = config.raw_regex.books.map(i => i[0]);
|
|
1505
1253
|
const dst = [...new Set(config.raw_regex.books.map(i => i[1]))];
|
|
1506
1254
|
const books = [...dst, ...src];
|
|
1255
|
+
|
|
1256
|
+
// Use enhanced processing if context-aware mode is enabled
|
|
1257
|
+
if (finalOptions.contextAware) {
|
|
1258
|
+
return detectReferencesWithContext(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// Fallback to original processing
|
|
1507
1262
|
return processReferenceDetection(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack);
|
|
1508
|
-
|
|
1509
1263
|
}
|
|
1510
1264
|
|
|
1511
1265
|
const getLanguageConfig = function(language) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripture-guide",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.83",
|
|
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": "dist/scriptures.cjs",
|
|
6
6
|
"module": "dist/scriptures.mjs",
|