@helloao/tools 0.1.0 → 0.3.0
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/cjs/generation/api.cjs +1580 -35
- package/dist/cjs/generation/api.cjs.map +3 -3
- package/dist/cjs/generation/audio.cjs +55 -8
- package/dist/cjs/generation/audio.cjs.map +2 -2
- package/dist/cjs/generation/book-order.cjs +1 -1
- package/dist/cjs/generation/book-order.cjs.map +2 -2
- package/dist/cjs/generation/common-types.cjs +996 -0
- package/dist/cjs/generation/common-types.cjs.map +2 -2
- package/dist/cjs/generation/dataset.cjs +44 -17
- package/dist/cjs/generation/dataset.cjs.map +2 -2
- package/dist/cjs/generation/index.cjs +8 -5
- package/dist/cjs/generation/index.cjs.map +2 -2
- package/dist/cjs/generation/simple.cjs +294 -0
- package/dist/cjs/generation/simple.cjs.map +7 -0
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/parser/codex-parser.cjs +3 -3
- package/dist/cjs/parser/codex-parser.cjs.map +3 -3
- package/dist/cjs/parser/commentary-csv-parser.cjs +14 -3
- package/dist/cjs/parser/commentary-csv-parser.cjs.map +3 -3
- package/dist/cjs/parser/index.cjs +1 -1
- package/dist/cjs/parser/lockman-parser.cjs +334 -0
- package/dist/cjs/parser/lockman-parser.cjs.map +7 -0
- package/dist/cjs/parser/tyndale-xml-parser.cjs +1 -1
- package/dist/cjs/parser/tyndale-xml-parser.cjs.map +1 -1
- package/dist/cjs/parser/types.cjs.map +1 -1
- package/dist/cjs/parser/usfm-parser.cjs +2 -2
- package/dist/cjs/parser/usfm-parser.cjs.map +1 -1
- package/dist/cjs/parser/usx-parser.cjs +145 -32
- package/dist/cjs/parser/usx-parser.cjs.map +2 -2
- package/dist/cjs/parser/words.cjs +187 -0
- package/dist/cjs/parser/words.cjs.map +7 -0
- package/dist/cjs/utils.cjs +152 -0
- package/dist/cjs/utils.cjs.map +3 -3
- package/dist/esm/generation/api.js +1527 -35
- package/dist/esm/generation/api.js.map +3 -3
- package/dist/esm/generation/audio.js +47 -4
- package/dist/esm/generation/audio.js.map +2 -2
- package/dist/esm/generation/book-order.js +1 -1
- package/dist/esm/generation/book-order.js.map +2 -2
- package/dist/esm/generation/common-types.js +903 -0
- package/dist/esm/generation/common-types.js.map +3 -3
- package/dist/esm/generation/dataset.js +35 -10
- package/dist/esm/generation/dataset.js.map +2 -2
- package/dist/esm/generation/index.js +2 -1
- package/dist/esm/generation/index.js.map +2 -2
- package/dist/esm/generation/simple.js +260 -0
- package/dist/esm/generation/simple.js.map +7 -0
- package/dist/esm/parser/codex-parser.js +3 -3
- package/dist/esm/parser/codex-parser.js.map +3 -3
- package/dist/esm/parser/commentary-csv-parser.js +3 -2
- package/dist/esm/parser/commentary-csv-parser.js.map +2 -2
- package/dist/esm/parser/lockman-parser.js +306 -0
- package/dist/esm/parser/lockman-parser.js.map +7 -0
- package/dist/esm/parser/tyndale-xml-parser.js +1 -1
- package/dist/esm/parser/tyndale-xml-parser.js.map +1 -1
- package/dist/esm/parser/usfm-parser.js +1 -1
- package/dist/esm/parser/usfm-parser.js.map +1 -1
- package/dist/esm/parser/usx-parser.js +153 -32
- package/dist/esm/parser/usx-parser.js.map +2 -2
- package/dist/esm/parser/words.js +149 -0
- package/dist/esm/parser/words.js.map +7 -0
- package/dist/esm/utils.js +138 -0
- package/dist/esm/utils.js.map +2 -2
- package/dist/types/generation/api.d.ts +8478 -472
- package/dist/types/generation/audio.d.ts +5 -0
- package/dist/types/generation/common-types.d.ts +1646 -407
- package/dist/types/generation/dataset.d.ts +1 -0
- package/dist/types/generation/index.d.ts +2 -1
- package/dist/types/generation/simple.d.ts +110 -0
- package/dist/types/parser/codex-parser.d.ts +18 -138
- package/dist/types/parser/commentary-csv-parser.d.ts +1 -1
- package/dist/types/parser/lockman-parser.d.ts +14 -0
- package/dist/types/parser/tyndale-xml-parser.d.ts +1 -1
- package/dist/types/parser/types.d.ts +67 -0
- package/dist/types/parser/usx-parser.d.ts +6 -5
- package/dist/types/parser/words.d.ts +104 -0
- package/dist/types/utils.d.ts +223 -18
- package/package.json +7 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Commentary, CommentaryBook, CommentaryBookChapter, CommentaryProfile, InputFile, Translation, TranslationBook, TranslationBookChapter, Dataset as CommonDataset, DatasetBook, DatasetBookChapter } from './common-types.js';
|
|
2
2
|
import { ParseMessage } from '../parser/types.js';
|
|
3
|
+
export declare const DATASET_VERSION = 1;
|
|
3
4
|
/**
|
|
4
5
|
* Defines an interface that contains generated dataset info.
|
|
5
6
|
*/
|
|
@@ -2,6 +2,7 @@ import * as api from './api.js';
|
|
|
2
2
|
import * as audio from './audio.js';
|
|
3
3
|
import * as dataset from './dataset.js';
|
|
4
4
|
import * as bookOrder from './book-order.js';
|
|
5
|
+
import * as simple from './simple.js';
|
|
5
6
|
export * from './common-types.js';
|
|
6
|
-
export { api, audio, dataset, bookOrder };
|
|
7
|
+
export { api, audio, dataset, bookOrder, simple };
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ChapterData, ChapterFootnote, ChapterHebrewSubtitle, ChapterVerse, ChapterWord, CommentaryChapterData, SimpleChapterData, SimpleChapterHebrewSubtitle, SimpleChapterVerse, SimpleChapterWord, SimpleCommentaryChapterData, SimpleInlineHeading, SimplePoemRange, SimpleTextRange, SimpleVerseFootnote, TranslationBookChapterWords, SimpleTranslationBookChapterWords } from './common-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The types of content that can be contained in a verse or Hebrew Subtitle.
|
|
4
|
+
*/
|
|
5
|
+
type VerseContent = ChapterVerse['content'][number] | ChapterHebrewSubtitle['content'][number];
|
|
6
|
+
/**
|
|
7
|
+
* The result of flattening the content of a verse into a single string.
|
|
8
|
+
*/
|
|
9
|
+
export interface SimplifiedVerseContent {
|
|
10
|
+
/**
|
|
11
|
+
* The text of the verse.
|
|
12
|
+
*/
|
|
13
|
+
text: string;
|
|
14
|
+
/**
|
|
15
|
+
* The footnotes that occur in the verse.
|
|
16
|
+
*/
|
|
17
|
+
footnotes: SimpleVerseFootnote[];
|
|
18
|
+
/**
|
|
19
|
+
* The headings that occur in the middle of the verse.
|
|
20
|
+
*/
|
|
21
|
+
headings: SimpleInlineHeading[];
|
|
22
|
+
/**
|
|
23
|
+
* The ranges of text that represent the Words of Jesus.
|
|
24
|
+
*/
|
|
25
|
+
wordsOfJesus: SimpleTextRange[];
|
|
26
|
+
/**
|
|
27
|
+
* The ranges of text that represent lines of poetry.
|
|
28
|
+
*/
|
|
29
|
+
poem: SimplePoemRange[];
|
|
30
|
+
/**
|
|
31
|
+
* The word-level annotations for the verse, with their offsets remapped onto the text.
|
|
32
|
+
*/
|
|
33
|
+
words: SimpleChapterWord[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Flattens the content of a verse into a single string, recording the positions of the
|
|
37
|
+
* footnotes, headings, and formatting that occur in it.
|
|
38
|
+
*
|
|
39
|
+
* The rules used to build the text are:
|
|
40
|
+
* - Strings and formatted text are appended as-is. The source data already contains the
|
|
41
|
+
* spacing that is needed between them.
|
|
42
|
+
* - Lines of poetry and line breaks start a new line.
|
|
43
|
+
* - Footnote and heading markers are replaced with a single space when one is needed to
|
|
44
|
+
* keep the surrounding words apart.
|
|
45
|
+
*
|
|
46
|
+
* All of the recorded offsets are measured in UTF-16 code units, which is what
|
|
47
|
+
* `String.prototype.slice()` and `String.prototype.length` use.
|
|
48
|
+
*
|
|
49
|
+
* Word-level annotations are anchored to a range of characters in a single item of the
|
|
50
|
+
* content array. Since the simplified format replaces that array with a single string,
|
|
51
|
+
* their offsets are remapped onto the text that is built here.
|
|
52
|
+
*
|
|
53
|
+
* @param content The content of the verse.
|
|
54
|
+
* @param footnotes The footnotes for the chapter, keyed by note ID.
|
|
55
|
+
* @param usedFootnotes A set that the IDs of the referenced footnotes are added to.
|
|
56
|
+
* @param words The word-level annotations for the verse.
|
|
57
|
+
*/
|
|
58
|
+
export declare function simplifyVerseContent(content: readonly VerseContent[], footnotes?: Map<number, ChapterFootnote>, usedFootnotes?: Set<number>, words?: readonly ChapterWord[]): SimplifiedVerseContent;
|
|
59
|
+
/**
|
|
60
|
+
* Converts the given verse into its simplified representation.
|
|
61
|
+
* @param verse The verse to convert.
|
|
62
|
+
* @param footnotes The footnotes for the chapter, keyed by note ID.
|
|
63
|
+
* @param usedFootnotes A set that the IDs of the referenced footnotes are added to.
|
|
64
|
+
* @param words The word-level annotations for the verse.
|
|
65
|
+
* @param remappedWords An array that the remapped word-level annotations are added to.
|
|
66
|
+
*/
|
|
67
|
+
export declare function simplifyVerse(verse: ChapterVerse, footnotes?: Map<number, ChapterFootnote>, usedFootnotes?: Set<number>, words?: readonly ChapterWord[], remappedWords?: SimpleChapterWord[]): SimpleChapterVerse;
|
|
68
|
+
/**
|
|
69
|
+
* Converts the given Hebrew Subtitle into its simplified representation.
|
|
70
|
+
* @param subtitle The subtitle to convert.
|
|
71
|
+
* @param footnotes The footnotes for the chapter, keyed by note ID.
|
|
72
|
+
* @param usedFootnotes A set that the IDs of the referenced footnotes are added to.
|
|
73
|
+
*/
|
|
74
|
+
export declare function simplifyHebrewSubtitle(subtitle: ChapterHebrewSubtitle, footnotes?: Map<number, ChapterFootnote>, usedFootnotes?: Set<number>): SimpleChapterHebrewSubtitle;
|
|
75
|
+
/**
|
|
76
|
+
* The result of converting a chapter into the simplified chapter format.
|
|
77
|
+
*/
|
|
78
|
+
export interface SimplifiedChapter {
|
|
79
|
+
/**
|
|
80
|
+
* The simplified chapter.
|
|
81
|
+
*/
|
|
82
|
+
chapter: SimpleChapterData;
|
|
83
|
+
/**
|
|
84
|
+
* The word-level annotations for the chapter, with their offsets remapped onto the
|
|
85
|
+
* text of each simplified verse. Empty if the chapter has no annotations.
|
|
86
|
+
*/
|
|
87
|
+
words: SimpleTranslationBookChapterWords;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Converts the given chapter into the simplified chapter format.
|
|
91
|
+
*
|
|
92
|
+
* In the simplified format, the content of each verse is a single string instead of a list
|
|
93
|
+
* of formatted content, and the footnotes are available on the verse that they occur in,
|
|
94
|
+
* along with the offset that they occur at.
|
|
95
|
+
*
|
|
96
|
+
* The word-level annotations are returned separately, since they are published in their
|
|
97
|
+
* own file. They are converted here because their offsets have to be remapped onto the
|
|
98
|
+
* text that is built for each verse.
|
|
99
|
+
*
|
|
100
|
+
* @param chapter The chapter to convert.
|
|
101
|
+
* @param words The word-level annotations for the chapter, keyed by verse number.
|
|
102
|
+
*/
|
|
103
|
+
export declare function simplifyChapter(chapter: ChapterData, words?: TranslationBookChapterWords): SimplifiedChapter;
|
|
104
|
+
/**
|
|
105
|
+
* Converts the given commentary chapter into the simplified chapter format.
|
|
106
|
+
* @param chapter The chapter to convert.
|
|
107
|
+
*/
|
|
108
|
+
export declare function simplifyCommentaryChapter(chapter: CommentaryChapterData): SimpleCommentaryChapterData;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=simple.d.ts.map
|
|
@@ -3,23 +3,9 @@ import { ParseTree } from './types.js';
|
|
|
3
3
|
export declare const chapterHeadingSchema: z.ZodObject<{
|
|
4
4
|
type: z.ZodLiteral<"chapter-heading">;
|
|
5
5
|
data: z.ZodObject<{
|
|
6
|
-
chapter: z.
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
}, {
|
|
10
|
-
chapter: number;
|
|
11
|
-
}>;
|
|
12
|
-
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
type: "chapter-heading";
|
|
14
|
-
data: {
|
|
15
|
-
chapter: number;
|
|
16
|
-
};
|
|
17
|
-
}, {
|
|
18
|
-
type: "chapter-heading";
|
|
19
|
-
data: {
|
|
20
|
-
chapter: number;
|
|
21
|
-
};
|
|
22
|
-
}>;
|
|
6
|
+
chapter: z.ZodCoercedNumber<unknown>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
}, z.core.$strip>;
|
|
23
9
|
export declare const verseSchema: z.ZodObject<{
|
|
24
10
|
type: z.ZodLiteral<"text">;
|
|
25
11
|
id: z.ZodString;
|
|
@@ -27,101 +13,31 @@ export declare const verseSchema: z.ZodObject<{
|
|
|
27
13
|
chapter: z.ZodOptional<z.ZodNumber>;
|
|
28
14
|
verse: z.ZodOptional<z.ZodNumber>;
|
|
29
15
|
data: z.ZodOptional<z.ZodObject<{
|
|
30
|
-
globalReferences: z.ZodOptional<z.ZodArray<z.ZodString
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
}, {
|
|
34
|
-
globalReferences?: string[] | undefined;
|
|
35
|
-
}>>;
|
|
36
|
-
}, "strip", z.ZodTypeAny, {
|
|
37
|
-
id: string;
|
|
38
|
-
type: "text";
|
|
39
|
-
chapter?: number | undefined;
|
|
40
|
-
verse?: number | undefined;
|
|
41
|
-
data?: {
|
|
42
|
-
globalReferences?: string[] | undefined;
|
|
43
|
-
} | undefined;
|
|
44
|
-
bookCode?: string | undefined;
|
|
45
|
-
}, {
|
|
46
|
-
id: string;
|
|
47
|
-
type: "text";
|
|
48
|
-
chapter?: number | undefined;
|
|
49
|
-
verse?: number | undefined;
|
|
50
|
-
data?: {
|
|
51
|
-
globalReferences?: string[] | undefined;
|
|
52
|
-
} | undefined;
|
|
53
|
-
bookCode?: string | undefined;
|
|
54
|
-
}>;
|
|
16
|
+
globalReferences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
55
19
|
export declare const paratextSchema: z.ZodObject<{
|
|
56
20
|
type: z.ZodLiteral<"paratext">;
|
|
57
21
|
id: z.ZodString;
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
type: "paratext";
|
|
61
|
-
}, {
|
|
62
|
-
id: string;
|
|
63
|
-
type: "paratext";
|
|
64
|
-
}>;
|
|
65
|
-
export declare const metadataSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export declare const metadataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
66
24
|
type: z.ZodLiteral<"chapter-heading">;
|
|
67
25
|
data: z.ZodObject<{
|
|
68
|
-
chapter: z.
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
}, {
|
|
72
|
-
chapter: number;
|
|
73
|
-
}>;
|
|
74
|
-
}, "strip", z.ZodTypeAny, {
|
|
75
|
-
type: "chapter-heading";
|
|
76
|
-
data: {
|
|
77
|
-
chapter: number;
|
|
78
|
-
};
|
|
79
|
-
}, {
|
|
80
|
-
type: "chapter-heading";
|
|
81
|
-
data: {
|
|
82
|
-
chapter: number;
|
|
83
|
-
};
|
|
84
|
-
}>, z.ZodObject<{
|
|
26
|
+
chapter: z.ZodCoercedNumber<unknown>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
85
29
|
type: z.ZodLiteral<"text">;
|
|
86
30
|
id: z.ZodString;
|
|
87
31
|
bookCode: z.ZodOptional<z.ZodString>;
|
|
88
32
|
chapter: z.ZodOptional<z.ZodNumber>;
|
|
89
33
|
verse: z.ZodOptional<z.ZodNumber>;
|
|
90
34
|
data: z.ZodOptional<z.ZodObject<{
|
|
91
|
-
globalReferences: z.ZodOptional<z.ZodArray<z.ZodString
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
}, {
|
|
95
|
-
globalReferences?: string[] | undefined;
|
|
96
|
-
}>>;
|
|
97
|
-
}, "strip", z.ZodTypeAny, {
|
|
98
|
-
id: string;
|
|
99
|
-
type: "text";
|
|
100
|
-
chapter?: number | undefined;
|
|
101
|
-
verse?: number | undefined;
|
|
102
|
-
data?: {
|
|
103
|
-
globalReferences?: string[] | undefined;
|
|
104
|
-
} | undefined;
|
|
105
|
-
bookCode?: string | undefined;
|
|
106
|
-
}, {
|
|
107
|
-
id: string;
|
|
108
|
-
type: "text";
|
|
109
|
-
chapter?: number | undefined;
|
|
110
|
-
verse?: number | undefined;
|
|
111
|
-
data?: {
|
|
112
|
-
globalReferences?: string[] | undefined;
|
|
113
|
-
} | undefined;
|
|
114
|
-
bookCode?: string | undefined;
|
|
115
|
-
}>, z.ZodObject<{
|
|
35
|
+
globalReferences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
116
38
|
type: z.ZodLiteral<"paratext">;
|
|
117
39
|
id: z.ZodString;
|
|
118
|
-
},
|
|
119
|
-
id: string;
|
|
120
|
-
type: "paratext";
|
|
121
|
-
}, {
|
|
122
|
-
id: string;
|
|
123
|
-
type: "paratext";
|
|
124
|
-
}>]>;
|
|
40
|
+
}, z.core.$strip>], "type">;
|
|
125
41
|
export declare const codexSchema: z.ZodObject<{
|
|
126
42
|
cells: z.ZodArray<z.ZodObject<{
|
|
127
43
|
kind: z.ZodNumber;
|
|
@@ -129,45 +45,9 @@ export declare const codexSchema: z.ZodObject<{
|
|
|
129
45
|
value: z.ZodString;
|
|
130
46
|
metadata: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
131
47
|
type: z.ZodString;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
type: z.ZodString;
|
|
136
|
-
}, z.ZodTypeAny, "passthrough">>>>;
|
|
137
|
-
}, "strip", z.ZodTypeAny, {
|
|
138
|
-
kind: number;
|
|
139
|
-
value: string;
|
|
140
|
-
languageId: string;
|
|
141
|
-
metadata?: z.objectOutputType<{
|
|
142
|
-
type: z.ZodString;
|
|
143
|
-
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
144
|
-
}, {
|
|
145
|
-
kind: number;
|
|
146
|
-
value: string;
|
|
147
|
-
languageId: string;
|
|
148
|
-
metadata?: z.objectInputType<{
|
|
149
|
-
type: z.ZodString;
|
|
150
|
-
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
151
|
-
}>, "many">;
|
|
152
|
-
}, "strip", z.ZodTypeAny, {
|
|
153
|
-
cells: {
|
|
154
|
-
kind: number;
|
|
155
|
-
value: string;
|
|
156
|
-
languageId: string;
|
|
157
|
-
metadata?: z.objectOutputType<{
|
|
158
|
-
type: z.ZodString;
|
|
159
|
-
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
160
|
-
}[];
|
|
161
|
-
}, {
|
|
162
|
-
cells: {
|
|
163
|
-
kind: number;
|
|
164
|
-
value: string;
|
|
165
|
-
languageId: string;
|
|
166
|
-
metadata?: z.objectInputType<{
|
|
167
|
-
type: z.ZodString;
|
|
168
|
-
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
169
|
-
}[];
|
|
170
|
-
}>;
|
|
48
|
+
}, z.core.$loose>>>;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
171
51
|
/**
|
|
172
52
|
* Defines a parser for codex files.
|
|
173
53
|
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ParseTree } from './types.js';
|
|
2
|
+
export declare const LOCKMAN_PARSER_VERSION = 3;
|
|
3
|
+
export declare class LockmanParser {
|
|
4
|
+
parse(text: string): ParseTree[];
|
|
5
|
+
private getBookIdFromVerseTag;
|
|
6
|
+
private parseVerseContent;
|
|
7
|
+
private addText;
|
|
8
|
+
private parseHebrewSubtitleContent;
|
|
9
|
+
private addSubtitleText;
|
|
10
|
+
private processFootnote;
|
|
11
|
+
private processFootnoteForSubtitle;
|
|
12
|
+
private extractFootnoteText;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=lockman-parser.d.ts.map
|
|
@@ -49,6 +49,69 @@ export interface Chapter {
|
|
|
49
49
|
* The list of footnotes for the chapter.
|
|
50
50
|
*/
|
|
51
51
|
footnotes: Footnote[];
|
|
52
|
+
/**
|
|
53
|
+
* The word-level annotations for the chapter's verses.
|
|
54
|
+
* Undefined if the source didn't contain any word-level annotations.
|
|
55
|
+
*/
|
|
56
|
+
words?: ChapterWords;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Defines the word-level annotations for a chapter, keyed by verse number.
|
|
60
|
+
*/
|
|
61
|
+
export type ChapterWords = {
|
|
62
|
+
[verseNumber: string]: ChapterWord[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Defines an interface that represents the annotations that a source associated
|
|
66
|
+
* with a specific range of characters in a verse.
|
|
67
|
+
*
|
|
68
|
+
* The range is anchored to a single item of the verse's content array, so that
|
|
69
|
+
* consumers can highlight the exact characters that an annotation applies to.
|
|
70
|
+
*/
|
|
71
|
+
export interface ChapterWord {
|
|
72
|
+
/**
|
|
73
|
+
* The index of the item in the verse's content array that the annotation applies to.
|
|
74
|
+
*/
|
|
75
|
+
contentIndex: number;
|
|
76
|
+
/**
|
|
77
|
+
* The index of the first character of the annotated word in the content item's text.
|
|
78
|
+
*/
|
|
79
|
+
start: number;
|
|
80
|
+
/**
|
|
81
|
+
* The index after the last character of the annotated word in the content item's text.
|
|
82
|
+
* That is, `text.slice(start, end)` is the annotated word.
|
|
83
|
+
*/
|
|
84
|
+
end: number;
|
|
85
|
+
/**
|
|
86
|
+
* The Strong's number(s) for the word.
|
|
87
|
+
* Undefined if the source only provided other annotations for the word.
|
|
88
|
+
*/
|
|
89
|
+
strongs?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* The dictionary (citation) form of the word.
|
|
92
|
+
* Taken from the `lemma` attribute.
|
|
93
|
+
*/
|
|
94
|
+
lemma?: string;
|
|
95
|
+
/**
|
|
96
|
+
* The morphology parse code for the word.
|
|
97
|
+
* Taken from the `x-morph` attribute.
|
|
98
|
+
*/
|
|
99
|
+
morph?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The pointer to the word in the source text, in the `<sourceName>:<location>` format.
|
|
102
|
+
* Taken from the `srcloc` attribute.
|
|
103
|
+
*/
|
|
104
|
+
srcloc?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Which occurrence of the source word this word is. 1-based.
|
|
107
|
+
* Taken from the `x-occurrence` attribute.
|
|
108
|
+
*/
|
|
109
|
+
occurrence?: number;
|
|
110
|
+
/**
|
|
111
|
+
* The total number of times that the source word occurs.
|
|
112
|
+
* Taken from the `x-occurrences` attribute.
|
|
113
|
+
*/
|
|
114
|
+
occurrences?: number;
|
|
52
115
|
}
|
|
53
116
|
/**
|
|
54
117
|
* Defines an interface that represents a hebrew subtitle.
|
|
@@ -94,6 +157,10 @@ export interface Text {
|
|
|
94
157
|
* This is only used for "hebrew subtitles" that are included inside the verse markers.
|
|
95
158
|
*/
|
|
96
159
|
descriptive?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Whether the text should be displayed in italics.
|
|
162
|
+
*/
|
|
163
|
+
italics?: boolean;
|
|
97
164
|
}
|
|
98
165
|
/**
|
|
99
166
|
* Defines an interface that represents a heading that is embedded in a verse.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types.js';
|
|
2
2
|
import { RewindableIterator } from './iterators.js';
|
|
3
|
+
import { AnnotatedContent } from './words.js';
|
|
3
4
|
/**
|
|
4
5
|
* The version of the parser.
|
|
5
6
|
* Used to determine whether input files need to be re-parsed.
|
|
6
7
|
*/
|
|
7
|
-
export declare const PARSER_VERSION =
|
|
8
|
+
export declare const PARSER_VERSION = 4;
|
|
8
9
|
/**
|
|
9
10
|
* Defines a class that is able to parse USX content.
|
|
10
11
|
*/
|
|
@@ -25,13 +26,13 @@ export declare class USXParser {
|
|
|
25
26
|
parse(usx: string): ParseTree;
|
|
26
27
|
iterateRootContent(usxElement: Element): Generator<ParseTree['content'][0]>;
|
|
27
28
|
iterateChapterContent(chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<ChapterContent>;
|
|
28
|
-
iterateVerseContent(chapter: Chapter, verse: Verse, nodes: RewindableIterator<Node
|
|
29
|
+
iterateVerseContent(chapter: Chapter, verse: Verse, nodes: RewindableIterator<Node>, previousVerse?: Verse | null): IterableIterator<string | FootnoteReference | Text | InlineLineBreak | AnnotatedContent<string | Text>>;
|
|
29
30
|
parseVerse(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): Verse;
|
|
30
31
|
parseHebrewSubtitle(para: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<HebrewSubtitle | Verse>;
|
|
31
|
-
iterateHebrewSubtitleContent(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<Verse | string | Text | FootnoteReference | InlineLineBreak
|
|
32
|
-
iterateNodeTextContent(nodes: RewindableIterator<Node>, node: Node, chapter: Chapter, verse?: Verse): IterableIterator<string | Text | FootnoteReference | InlineLineBreak
|
|
32
|
+
iterateHebrewSubtitleContent(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<Verse | string | Text | FootnoteReference | InlineLineBreak | AnnotatedContent<string | Text>>;
|
|
33
|
+
iterateNodeTextContent(nodes: RewindableIterator<Node>, node: Node, chapter: Chapter, verse?: Verse): IterableIterator<string | Text | FootnoteReference | InlineLineBreak | AnnotatedContent<string | Text>>;
|
|
33
34
|
iterateCharContent(char: Element): IterableIterator<string | Text>;
|
|
34
35
|
iterateNote(nodes: RewindableIterator<Node>, node: Element, chapter: Chapter, verse?: Verse): IterableIterator<FootnoteReference>;
|
|
35
|
-
iterateChar(nodes: RewindableIterator<Node>, node: Element): IterableIterator<string | Text
|
|
36
|
+
iterateChar(nodes: RewindableIterator<Node>, node: Element): IterableIterator<string | Text | AnnotatedContent<string | Text>>;
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=usx-parser.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Chapter, ChapterWord } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The annotations that a source associated with a word, without any information
|
|
4
|
+
* about where the word is located.
|
|
5
|
+
*/
|
|
6
|
+
export type WordAnnotations = Omit<ChapterWord, 'contentIndex' | 'start' | 'end'>;
|
|
7
|
+
/**
|
|
8
|
+
* Defines an interface that represents a range of characters within a single
|
|
9
|
+
* piece of text, along with the annotations that apply to it.
|
|
10
|
+
*/
|
|
11
|
+
export interface WordRange {
|
|
12
|
+
/**
|
|
13
|
+
* The index of the first character of the word.
|
|
14
|
+
*/
|
|
15
|
+
start: number;
|
|
16
|
+
/**
|
|
17
|
+
* The index after the last character of the word.
|
|
18
|
+
*/
|
|
19
|
+
end: number;
|
|
20
|
+
/**
|
|
21
|
+
* The annotations that apply to the word.
|
|
22
|
+
*/
|
|
23
|
+
annotations: WordAnnotations;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Defines an interface that pairs a piece of verse content with the word
|
|
27
|
+
* annotations that apply to it, so that the annotations can be passed along
|
|
28
|
+
* with the content while it is being parsed.
|
|
29
|
+
*
|
|
30
|
+
* The ranges are relative to the text of the content, and are never included in
|
|
31
|
+
* the final parse tree.
|
|
32
|
+
*/
|
|
33
|
+
export interface AnnotatedContent<T> {
|
|
34
|
+
/**
|
|
35
|
+
* The content that the annotations apply to.
|
|
36
|
+
*/
|
|
37
|
+
annotatedContent: T;
|
|
38
|
+
/**
|
|
39
|
+
* The ranges of the content that are annotated.
|
|
40
|
+
*/
|
|
41
|
+
words: WordRange[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether the given value is content that has word annotations
|
|
45
|
+
* attached to it.
|
|
46
|
+
* @param value The value to test.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isAnnotatedContent(value: unknown): value is AnnotatedContent<unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Reads the word annotations that are attached to the given element.
|
|
51
|
+
* Returns null if the element doesn't have any recognized annotations.
|
|
52
|
+
* @param element The element to read the annotations from.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readWordAnnotations(element: Element): WordAnnotations | null;
|
|
55
|
+
/**
|
|
56
|
+
* Shrinks the given range so that it doesn't include any leading or trailing
|
|
57
|
+
* whitespace. Returns null if the range only contains whitespace.
|
|
58
|
+
* @param text The text that the range is in.
|
|
59
|
+
* @param start The index of the first character of the range.
|
|
60
|
+
* @param end The index after the last character of the range.
|
|
61
|
+
*/
|
|
62
|
+
export declare function trimWordRange(text: string, start: number, end: number): {
|
|
63
|
+
start: number;
|
|
64
|
+
end: number;
|
|
65
|
+
} | null;
|
|
66
|
+
/**
|
|
67
|
+
* Collapses the whitespace in the given text in the same manner that the
|
|
68
|
+
* parsers normalize text (each run of whitespace becomes a single space, and the
|
|
69
|
+
* result is trimmed), and returns a map from the indexes in the given text to
|
|
70
|
+
* the indexes in the returned text.
|
|
71
|
+
*
|
|
72
|
+
* The map contains an entry for every index in the given text, plus one for the
|
|
73
|
+
* index just past the end of it, so that both ends of a range can be mapped.
|
|
74
|
+
* @param text The text to collapse.
|
|
75
|
+
*/
|
|
76
|
+
export declare function collapseWhitespaceMap(text: string): {
|
|
77
|
+
text: string;
|
|
78
|
+
map: number[];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Moves the words that apply to the given content item to the indexes that they
|
|
82
|
+
* have after the item's text was collapsed with collapseWhitespaceMap().
|
|
83
|
+
* Words that no longer cover any characters are removed.
|
|
84
|
+
* @param words The words to remap.
|
|
85
|
+
* @param contentIndex The index of the content item that was collapsed.
|
|
86
|
+
* @param map The index map that collapseWhitespaceMap() returned.
|
|
87
|
+
*/
|
|
88
|
+
export declare function remapChapterWords(words: ChapterWord[], contentIndex: number, map: number[]): void;
|
|
89
|
+
/**
|
|
90
|
+
* Removes the words that apply to the given content item, and moves the words
|
|
91
|
+
* that apply to later items back by one to account for the item being removed.
|
|
92
|
+
* @param words The words to update.
|
|
93
|
+
* @param contentIndex The index of the content item that was removed.
|
|
94
|
+
*/
|
|
95
|
+
export declare function removeChapterWordsForContent(words: ChapterWord[], contentIndex: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Adds the given words to the chapter for the given verse number.
|
|
98
|
+
* Does nothing if there are no words.
|
|
99
|
+
* @param chapter The chapter to add the words to.
|
|
100
|
+
* @param verseNumber The number of the verse that the words are in.
|
|
101
|
+
* @param words The words to add.
|
|
102
|
+
*/
|
|
103
|
+
export declare function addChapterWords(chapter: Chapter, verseNumber: number, words: ChapterWord[]): void;
|
|
104
|
+
//# sourceMappingURL=words.d.ts.map
|