proskomma-core 0.9.10 → 0.9.13

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.
Files changed (136) hide show
  1. package/.eslintrc.json +79 -0
  2. package/.gitattributes +2 -0
  3. package/docs/_config.yml +1 -0
  4. package/docs/index.md +3 -0
  5. package/docs/pk_edit_0_9.odt +0 -0
  6. package/docs/pk_edit_0_9.pdf +0 -0
  7. package/docs/proskomma_101_slideshow.odp +0 -0
  8. package/docs/proskomma_101_slideshow.pdf +0 -0
  9. package/docs/proskomma_edit_html.png +0 -0
  10. package/docs/proskomma_edit_html.svg +451 -0
  11. package/docs/proskomma_edit_reference.png +0 -0
  12. package/docs/proskomma_edit_reference.svg +349 -0
  13. package/docs/repo_logo.png +0 -0
  14. package/esm/package.json +3 -0
  15. package/esm/wrapper.mjs +5 -0
  16. package/index.cjs +6 -0
  17. package/package.json +18 -15
  18. package/src/graph/index.cjs +201 -0
  19. package/src/graph/lib/do_cv.cjs +249 -0
  20. package/src/graph/lib/dump.cjs +40 -0
  21. package/src/graph/lib/remake_blocks.cjs +57 -0
  22. package/src/graph/lib/sequence_chars.cjs +84 -0
  23. package/src/graph/lib/sort.cjs +39 -0
  24. package/src/graph/lib/tribos.cjs +97 -0
  25. package/src/graph/lib/tribos_expression.cjs +556 -0
  26. package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
  27. package/src/graph/lib/tribos_step.cjs +434 -0
  28. package/src/graph/mutations/add.cjs +91 -0
  29. package/src/graph/mutations/delete.cjs +61 -0
  30. package/src/graph/mutations/index.cjs +54 -0
  31. package/src/graph/mutations/rehash.cjs +17 -0
  32. package/src/graph/mutations/tags.cjs +120 -0
  33. package/src/graph/mutations/update.cjs +210 -0
  34. package/src/graph/mutations/versification.cjs +96 -0
  35. package/src/graph/queries/block.cjs +228 -0
  36. package/src/graph/queries/cIndex.cjs +87 -0
  37. package/src/graph/queries/cell.cjs +42 -0
  38. package/src/graph/queries/cv.cjs +19 -0
  39. package/src/graph/queries/cvBook.cjs +16 -0
  40. package/src/graph/queries/cvChapter.cjs +16 -0
  41. package/src/graph/queries/cvIndex.cjs +47 -0
  42. package/src/graph/queries/cvNavigation.cjs +116 -0
  43. package/src/graph/queries/cvVerseElement.cjs +84 -0
  44. package/src/graph/queries/cvVerses.cjs +14 -0
  45. package/src/graph/queries/doc_set.cjs +220 -0
  46. package/src/graph/queries/document.cjs +555 -0
  47. package/src/graph/queries/idParts.cjs +30 -0
  48. package/src/graph/queries/index.cjs +151 -0
  49. package/src/graph/queries/inputBlockSpec.cjs +17 -0
  50. package/src/graph/queries/inputItemObject.cjs +12 -0
  51. package/src/graph/queries/input_att_spec.cjs +14 -0
  52. package/src/graph/queries/input_key_matches.cjs +11 -0
  53. package/src/graph/queries/input_key_value.cjs +11 -0
  54. package/src/graph/queries/input_key_values.cjs +11 -0
  55. package/src/graph/queries/input_selector_spec.cjs +19 -0
  56. package/src/graph/queries/item.cjs +71 -0
  57. package/src/graph/queries/itemGroup.cjs +75 -0
  58. package/src/graph/queries/key_value.cjs +18 -0
  59. package/src/graph/queries/kv_entry.cjs +21 -0
  60. package/src/graph/queries/kv_sequence.cjs +151 -0
  61. package/src/graph/queries/node.cjs +44 -0
  62. package/src/graph/queries/orig.cjs +11 -0
  63. package/src/graph/queries/regex_index.cjs +18 -0
  64. package/src/graph/queries/row_equals_spec.cjs +11 -0
  65. package/src/graph/queries/row_match_spec.cjs +11 -0
  66. package/src/graph/queries/selector_spec.cjs +29 -0
  67. package/src/graph/queries/sequence.cjs +314 -0
  68. package/src/graph/queries/table_sequence.cjs +192 -0
  69. package/src/graph/queries/tree_sequence.cjs +58 -0
  70. package/src/graph/queries/verseNumber.cjs +44 -0
  71. package/src/graph/queries/verseRange.cjs +11 -0
  72. package/src/graph/queries/versification.cjs +25 -0
  73. package/src/index.cjs +583 -0
  74. package/src/model/doc_set.cjs +389 -0
  75. package/src/model/doc_set_helpers/block.cjs +232 -0
  76. package/src/model/doc_set_helpers/enum.cjs +87 -0
  77. package/src/model/doc_set_helpers/item.cjs +198 -0
  78. package/src/model/doc_set_helpers/rehash.cjs +53 -0
  79. package/src/model/doc_set_helpers/selectors.cjs +58 -0
  80. package/src/model/doc_set_helpers/serialize.cjs +22 -0
  81. package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
  82. package/src/model/doc_set_helpers/update.cjs +290 -0
  83. package/src/model/document.cjs +369 -0
  84. package/src/model/document_helpers/blocks.cjs +135 -0
  85. package/src/model/document_helpers/chapter_verse.cjs +291 -0
  86. package/src/model/document_helpers/pre_enums.cjs +67 -0
  87. package/src/model/document_helpers/sequences.cjs +205 -0
  88. package/src/model/document_helpers/serialize_succinct.cjs +55 -0
  89. package/src/model/document_helpers/succinct_filter.cjs +102 -0
  90. package/src/model/versifications/eng_vrs.cjs +455 -0
  91. package/src/model/versifications/index.cjs +38 -0
  92. package/src/model/versifications/lxx_vrs.cjs +950 -0
  93. package/src/model/versifications/org_vrs.cjs +155 -0
  94. package/src/model/versifications/rsc_vrs.cjs +342 -0
  95. package/src/model/versifications/rso_vrs.cjs +541 -0
  96. package/src/model/versifications/vul_vrs.cjs +835 -0
  97. package/src/parser/index.cjs +506 -0
  98. package/src/parser/lexers/index.cjs +11 -0
  99. package/src/parser/lexers/lexingRegexes.cjs +45 -0
  100. package/src/parser/lexers/nodes.cjs +123 -0
  101. package/src/parser/lexers/object_for_fragment.cjs +123 -0
  102. package/src/parser/lexers/tsv.cjs +45 -0
  103. package/src/parser/lexers/usfm.cjs +17 -0
  104. package/src/parser/lexers/usx/index.cjs +7 -0
  105. package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
  106. package/src/parser/lib/tokenize.cjs +37 -0
  107. package/src/parser/model/index.cjs +637 -0
  108. package/src/parser/parser_specs.cjs +781 -0
  109. package/src/pipelines/perf2x/index.cjs +7 -0
  110. package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
  111. package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
  112. package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
  113. package/src/transforms/index.cjs +9 -0
  114. package/src/transforms/perf2PkJson.cjs +534 -0
  115. package/src/transforms/perf2usfm.cjs +294 -0
  116. package/src/util/byteArray.cjs +251 -0
  117. package/src/util/canons.cjs +117 -0
  118. package/src/util/enums.cjs +41 -0
  119. package/src/util/generateId.cjs +6 -0
  120. package/src/util/graftDefs.cjs +15 -0
  121. package/src/util/index.cjs +29 -0
  122. package/src/util/inspectSuccinct.cjs +59 -0
  123. package/src/util/itemDefs.cjs +33 -0
  124. package/src/util/parserConstantDefs.cjs +30 -0
  125. package/src/util/scopeDefs.cjs +173 -0
  126. package/src/util/scriptlike/blocksSpec.cjs +192 -0
  127. package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
  128. package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
  129. package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
  130. package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
  131. package/src/util/succinct.cjs +159 -0
  132. package/src/util/tags.cjs +28 -0
  133. package/src/util/tokenDefs.cjs +27 -0
  134. package/src/util/versification.cjs +364 -0
  135. package/dist/index.js +0 -8
  136. package/dist/index.js.LICENSE.txt +0 -23
@@ -0,0 +1,6 @@
1
+ const UUID = require('pure-uuid');
2
+ const btoa = require('btoa');
3
+
4
+ const generateId = () => btoa(new UUID(4)).substring(0, 12);
5
+
6
+ module.exports = { generateId };
@@ -0,0 +1,15 @@
1
+ const graftLocation = {
2
+ heading: 'block',
3
+ title: 'block',
4
+ endTitle: 'block',
5
+ remark: 'block',
6
+ footnote: 'inline',
7
+ xref: 'inline',
8
+ noteCaller: 'inline',
9
+ esbCat: 'inline',
10
+ table: 'block',
11
+ tree: 'block',
12
+ kv: 'block',
13
+ };
14
+
15
+ module.exports = { graftLocation };
@@ -0,0 +1,29 @@
1
+ const ByteArray = require('./byteArray.cjs');
2
+ const canons = require('./canons.cjs');
3
+ const enums = require('./enums.cjs');
4
+ const { generateId } = require('./generateId.cjs');
5
+ const graftDefs = require('./graftDefs.cjs');
6
+ const inspect = require('./inspectSuccinct.cjs');
7
+ const itemDefs = require('./itemDefs.cjs');
8
+ const parserConstants = require('./parserConstantDefs.cjs');
9
+ const scopeDefs = require('./scopeDefs.cjs');
10
+ const succinct = require('./succinct.cjs');
11
+ const tags = require('./tags.cjs');
12
+ const tokenDefs = require('./tokenDefs.cjs');
13
+ const versification = require('./versification.cjs');
14
+
15
+ module.exports = {
16
+ ByteArray,
17
+ canons,
18
+ enums,
19
+ generateId,
20
+ graftDefs,
21
+ inspect,
22
+ itemDefs,
23
+ parserConstants,
24
+ scopeDefs,
25
+ succinct,
26
+ tags,
27
+ tokenDefs,
28
+ versification,
29
+ };
@@ -0,0 +1,59 @@
1
+ const ByteArray = require('./byteArray.cjs');
2
+ const succinct = require('./succinct.cjs');
3
+ const itemDefs = require('./itemDefs.cjs');
4
+ const tokenDefs = require('./tokenDefs.cjs');
5
+ const scopeDefs = require('./scopeDefs.cjs');
6
+
7
+ const inspectEnum = enumString => {
8
+ const ba = new ByteArray();
9
+ ba.fromBase64(enumString);
10
+ const ret = [];
11
+ ret.push(`* Char length ${ba.length} *`);
12
+
13
+ for (const [count, text] of succinct.unpackEnum(ba, true)) {
14
+ ret.push(`${count}\t"${text}"`);
15
+ }
16
+ return ret.join('\n');
17
+ };
18
+
19
+ const inspectSuccinct = (succinctdoc, enumStrings) => {
20
+ const ba = new ByteArray();
21
+ ba.fromBase64(succinctdoc);
22
+ const enums = {};
23
+
24
+ for (const [category, enumString] of Object.entries(enumStrings)) {
25
+ enums[category] = new ByteArray();
26
+ enums[category].fromBase64(enumString);
27
+ }
28
+
29
+ const indexes = succinct.enumIndexes(enums);
30
+ const ret = [];
31
+ ret.push(`* Char length ${ba.length} *`);
32
+ let pos = 0;
33
+
34
+ while (pos < ba.length) {
35
+ const [itemLength, itemType, itemSubtype] = succinct.headerBytes(ba, pos);
36
+ let subtypeLabel = itemSubtype;
37
+ let extra = '';
38
+
39
+ switch (itemDefs.itemEnumLabels[itemType]) {
40
+ case 'token':
41
+ subtypeLabel = tokenDefs.tokenEnumLabels[itemSubtype];
42
+ extra = `"${succinct.succinctTokenChars(enums, indexes, ba, itemSubtype, pos)}"`;
43
+ break;
44
+ case 'startScope':
45
+ case 'endScope':
46
+ subtypeLabel = scopeDefs.scopeEnumLabels[itemSubtype];
47
+ extra = succinct.succinctScopeLabel(enums, indexes, ba, itemSubtype, pos);
48
+ break;
49
+ case 'graft':
50
+ subtypeLabel = succinct.succinctGraftName(enums, indexes, itemSubtype);
51
+ extra = succinct.succinctGraftSeqId(enums, indexes, ba, pos);
52
+ }
53
+ ret.push(`${itemDefs.itemEnumLabels[itemType]}\t${subtypeLabel}\t(${itemLength})\t${extra}`);
54
+ pos += itemLength;
55
+ }
56
+ return ret.join('\n');
57
+ };
58
+
59
+ module.exports = { inspectEnum, inspectSuccinct };
@@ -0,0 +1,33 @@
1
+ const itemEnum = {
2
+ token: 0,
3
+ graft: 1,
4
+ startScope: 2,
5
+ endScope: 3,
6
+ };
7
+
8
+ const itemEnumLabels = Object.entries(itemEnum).sort((a, b) => a[1] - b[1]).map(kv => kv[0]);
9
+
10
+ const itemArray2Object = a => ({
11
+ type: a[0],
12
+ subType: a[1],
13
+ payload: a[2],
14
+ });
15
+
16
+ const itemObject2Array = ob => [
17
+ ob.type,
18
+ ob.subType,
19
+ ob.payload,
20
+ ];
21
+
22
+ const itemArrays2Objects = aa => aa.map(a => itemArray2Object(a));
23
+
24
+ const itemObjects2Arrays = obs => obs.map(ob => itemObject2Array(ob));
25
+
26
+ module.exports = {
27
+ itemEnum,
28
+ itemEnumLabels,
29
+ itemArray2Object,
30
+ itemObject2Array,
31
+ itemArrays2Objects,
32
+ itemObjects2Arrays,
33
+ };
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ usfm: {
3
+ baseSequenceTypes: {
4
+ main: '1',
5
+ introduction: '*',
6
+ introTitle: '?',
7
+ introEndTitle: '?',
8
+ title: '?',
9
+ endTitle: '?',
10
+ heading: '*',
11
+ header: '*',
12
+ remark: '*',
13
+ sidebar: '*',
14
+ table: '*',
15
+ tree: '*',
16
+ kv: '*',
17
+ },
18
+ inlineSequenceTypes: {
19
+ footnote: '*',
20
+ noteCaller: '*',
21
+ xref: '*',
22
+ pubNumber: '*',
23
+ altNumber: '*',
24
+ esbCat: '*',
25
+ fig: '*',
26
+ temp: '?',
27
+ },
28
+ },
29
+ };
30
+
@@ -0,0 +1,173 @@
1
+ const xre = require('xregexp');
2
+
3
+ const scopeEnum = {
4
+ 'blockTag': 0,
5
+ 'inline': 1,
6
+ 'chapter': 2,
7
+ 'pubChapter': 3,
8
+ 'altChapter': 4,
9
+ 'verses': 5,
10
+ 'verse': 6,
11
+ 'pubVerse': 7,
12
+ 'altVerse': 8,
13
+ 'esbCat': 9,
14
+ 'span': 10,
15
+ 'table': 11,
16
+ 'cell': 12,
17
+ 'milestone': 13,
18
+ 'spanWithAtts': 14,
19
+ 'attribute': 15,
20
+ 'hangingGraft': 16,
21
+ 'orphanTokens': 17,
22
+ 'tTableRow': 18,
23
+ 'tTableCol': 19,
24
+ 'tTreeNode': 20,
25
+ 'tTreeParent': 21,
26
+ 'tTreeChild': 22,
27
+ 'tTreeContent': 23,
28
+ 'kvPrimary': 24,
29
+ 'kvSecondary': 25,
30
+ 'kvField': 26,
31
+ };
32
+
33
+ const scopeEnumLabels = Object.entries(scopeEnum).sort((a, b) => a[1] - b[1]).map(kv => kv[0]);
34
+
35
+ const splitTagNumber = fullTagName => {
36
+ const tagBits = xre.exec(fullTagName, xre('([^1-9]+)(.*)'));
37
+ const tagName = tagBits[1];
38
+ const tagNo = tagBits[2].length > 0 ? tagBits[2] : '1';
39
+ return [tagName, tagNo];
40
+ };
41
+
42
+ const cellScope = fullTagName => {
43
+ const tagProps = {
44
+ 'th': {
45
+ type: 'colHeading',
46
+ align: 'left',
47
+ },
48
+ 'thr': {
49
+ type: 'colHeading',
50
+ align: 'right',
51
+ },
52
+ 'tc': {
53
+ type: 'body',
54
+ align: 'left',
55
+ },
56
+ 'tcr': {
57
+ type: 'body',
58
+ align: 'right',
59
+ },
60
+ };
61
+ const [tagName, tagNo] = splitTagNumber(fullTagName);
62
+ let tagField = '1';
63
+
64
+ if (tagNo.includes('-')) {
65
+ const [fromN, toN] = tagNo.split('-');
66
+ tagField = `${(parseInt(toN) - parseInt(fromN)) + 1}`;
67
+ }
68
+ return `cell/${tagProps[tagName].type}/${tagProps[tagName].align}/${tagField}`;
69
+ };
70
+
71
+ const labelForScope = (scopeType, scopeFields) => {
72
+ switch (scopeType) {
73
+ case 'blockTag':
74
+ return `blockTag/${scopeFields[0]}`;
75
+ case 'inline':
76
+ return `inline/${scopeFields[0]}`;
77
+ case 'chapter':
78
+ return `chapter/${scopeFields[0]}`;
79
+ case 'verses':
80
+ return `verses/${scopeFields[0]}`;
81
+ case 'verse':
82
+ return `verse/${scopeFields[0]}`;
83
+ case 'span':
84
+ return `span/${scopeFields[0]}`;
85
+ case 'table':
86
+ return 'table';
87
+ case 'cell':
88
+ return cellScope(scopeFields[0]);
89
+ case 'milestone':
90
+ return `milestone/${scopeFields[0]}`;
91
+ case 'spanWithAtts':
92
+ return `spanWithAtts/${scopeFields[0]}`;
93
+ case 'attribute':
94
+ return `attribute/${scopeFields[0]}/${scopeFields[1]}/${scopeFields[2]}/${scopeFields[3]}`;
95
+ case 'orphanTokens':
96
+ return `orphanTokens`;
97
+ case 'hangingGraft':
98
+ return `hangingGraft`;
99
+ case 'pubChapter':
100
+ return `pubChapter/${scopeFields[0]}`;
101
+ case 'pubVerse':
102
+ return `pubVerse/${scopeFields[0]}`;
103
+ case 'altChapter':
104
+ return `altChapter/${scopeFields[0]}`;
105
+ case 'altVerse':
106
+ return `altVerse/${scopeFields[0]}`;
107
+ case 'esbCat':
108
+ return `esbCat/${scopeFields[0]}`;
109
+ case 'tTableRow':
110
+ return `tTableRow/${scopeFields[0]}`;
111
+ case 'tTableCol':
112
+ return `tTableCol/${scopeFields[0]}`;
113
+ case 'tTreeNode':
114
+ return `tTreeNode/${scopeFields[0]}`;
115
+ case 'tTreeParent':
116
+ return `tTreeParent/${scopeFields[0]}`;
117
+ case 'tTreeChild':
118
+ return `tTreeChild/${scopeFields[0]}/${scopeFields[1]}`;
119
+ case 'tTreeContent':
120
+ return `tTreeContent/${scopeFields[0]}`;
121
+ case 'kvPrimary':
122
+ return `kvPrimary/${scopeFields[0]}`;
123
+ case 'kvSecondary':
124
+ return `kvSecondary/${scopeFields[0]}/${scopeFields[1]}`;
125
+ case 'kvField':
126
+ return `kvField/${scopeFields[0]}`;
127
+ default:
128
+ throw new Error(`Unknown scope type '${scopeType}' in labelForScope`);
129
+ }
130
+ };
131
+
132
+ const nComponentsForScope = (scopeType) => {
133
+ switch (scopeType) {
134
+ case 'orphanTokens':
135
+ case 'hangingGraft':
136
+ case 'table':
137
+ return 1;
138
+ case 'blockTag':
139
+ case 'inline':
140
+ case 'chapter':
141
+ case 'verses':
142
+ case 'verse':
143
+ case 'span':
144
+ case 'milestone':
145
+ case 'spanWithAtts':
146
+ case 'pubChapter':
147
+ case 'altChapter':
148
+ case 'pubVerse':
149
+ case 'altVerse':
150
+ case 'esbCat':
151
+ case 'tTableRow':
152
+ case 'tTableCol':
153
+ case 'tTreeNode':
154
+ case 'tTreeParent':
155
+ case 'tTreeContent':
156
+ case 'kvPrimary':
157
+ case 'kvField':
158
+ return 2;
159
+ case 'tTreeChild':
160
+ case 'kvSecondary':
161
+ return 3;
162
+ case 'cell':
163
+ return 4;
164
+ case 'attribute':
165
+ return 6;
166
+ default:
167
+ throw new Error(`Unknown scope type '${scopeType}' in nComponentsForScope`);
168
+ }
169
+ };
170
+
171
+ module.exports = {
172
+ scopeEnum, scopeEnumLabels, labelForScope, nComponentsForScope,
173
+ };
@@ -0,0 +1,192 @@
1
+ const utils = require('../index.cjs');
2
+ const { labelForScope } = utils.scopeDefs;
3
+ const { tokenizeString } = require('../../parser/lib/tokenize.cjs');
4
+ const {
5
+ flattenNodes,
6
+ numberNodes,
7
+ } = require('../../parser/lexers/nodes.cjs');
8
+
9
+ const tsvToInputBlock = (tsv, hasHeadings) => {
10
+ const ret = [];
11
+ const rows = tsv.split(/[\n\r]+/);
12
+
13
+ for (const [rowN, rowTSV] of rows.entries()) {
14
+ if (hasHeadings && rowN === 0) {
15
+ continue;
16
+ }
17
+
18
+ const row = rowTSV.split('\t');
19
+
20
+ for (const [cellN, cellString] of row.entries()) {
21
+ const cellRecord = {
22
+ os: [],
23
+ bg: [],
24
+ bs: {
25
+ type: 'scope',
26
+ subType: 'start',
27
+ payload: labelForScope('tTableRow', [`${rowN}`]),
28
+ },
29
+ is: [],
30
+ items: [],
31
+ };
32
+ const colScope = `tTableCol/${cellN}`;
33
+
34
+ cellRecord.is.push({
35
+ type: 'scope',
36
+ subType: 'start',
37
+ payload: colScope,
38
+ });
39
+ cellRecord.items.push({
40
+ type: 'scope',
41
+ subType: 'start',
42
+ payload: colScope,
43
+ });
44
+
45
+ for (const [token, tokenType] of tokenizeString(cellString)) {
46
+ cellRecord.items.push({
47
+ type: 'token',
48
+ subType: tokenType,
49
+ payload: token,
50
+ });
51
+ }
52
+ cellRecord.items.push({
53
+ type: 'scope',
54
+ subType: 'end',
55
+ payload: colScope,
56
+ });
57
+ ret.push(cellRecord);
58
+ }
59
+ }
60
+ return ret;
61
+ };
62
+
63
+ const tsvHeadingTags = tsv => {
64
+ const firstRow = tsv.split(/[\n\r]+/)[0];
65
+ return firstRow.split('\t').map((c, n) => `col${n}:${c.trim()}`);
66
+ };
67
+
68
+ const treeToInputBlock = treeJson => {
69
+ const ret = [];
70
+
71
+ for (const node of flattenNodes(numberNodes(treeJson))) {
72
+ const nodeRecord = {
73
+ os: [],
74
+ bg: [],
75
+ bs: {
76
+ type: 'scope',
77
+ subType: 'start',
78
+ payload: labelForScope('tTreeNode', [`${node.id}`]),
79
+ },
80
+ is: [],
81
+ items: [],
82
+ };
83
+ const scopePayload = labelForScope('tTreeParent', [`${node.parentId}`]);
84
+
85
+ nodeRecord.items.push({
86
+ type: 'scope',
87
+ subType: 'start',
88
+ payload: scopePayload,
89
+ });
90
+
91
+ nodeRecord.is.push({
92
+ type: 'scope',
93
+ subType: 'start',
94
+ payload: scopePayload,
95
+ });
96
+
97
+ if (node.content) {
98
+ for (const [name, content] of Object.entries(node.content)) {
99
+ const treeContentStart = nodeRecord.items.length;
100
+ const tokenized = tokenizeString(content);
101
+ const scopePayload = labelForScope('tTreeContent', [name, node.id, `${treeContentStart}`, `${tokenized.length}`]);
102
+
103
+ nodeRecord.items.push({
104
+ type: 'scope',
105
+ subType: 'start',
106
+ payload: scopePayload,
107
+ });
108
+
109
+ nodeRecord.is.push({
110
+ type: 'scope',
111
+ subType: 'start',
112
+ payload: scopePayload,
113
+ });
114
+
115
+ for (const [payload, subType] of tokenized) {
116
+ nodeRecord.items.push({
117
+ type: 'token',
118
+ subType,
119
+ payload,
120
+ });
121
+ }
122
+ nodeRecord.items.push({
123
+ type: 'scope',
124
+ subType: 'end',
125
+ payload: scopePayload,
126
+ });
127
+ }
128
+ }
129
+
130
+ if (node.children) {
131
+ for (const [childN, childNodeN] of node.children.entries()) {
132
+ const scopePayload = labelForScope('tTreeChild', [childN, childNodeN]);
133
+
134
+ nodeRecord.items.push({
135
+ type: 'scope',
136
+ subType: 'start',
137
+ payload: scopePayload,
138
+ });
139
+ nodeRecord.is.push({
140
+ type: 'scope',
141
+ subType: 'start',
142
+ payload: scopePayload,
143
+ });
144
+ nodeRecord.items.push({
145
+ type: 'scope',
146
+ subType: 'end',
147
+ payload: scopePayload,
148
+ });
149
+ }
150
+ }
151
+ nodeRecord.items.push({
152
+ type: 'scope',
153
+ subType: 'end',
154
+ payload: scopePayload,
155
+ });
156
+ ret.push(nodeRecord);
157
+ }
158
+ return ret;
159
+ };
160
+
161
+ const escapePayload =
162
+ str =>
163
+ str.replace(/\\/g, '\\\\')
164
+ .replace(/"/g, '\\"')
165
+ .replace(/\n/g, '\\n')
166
+ .replace(/\t/g, '\\t')
167
+ .replace(/\r/g, '\\r');
168
+
169
+ const object2Query = obs =>
170
+ '[' +
171
+ obs.map(
172
+ ob => `\n {\n type: "${ob.type}" \n subType: "${ob.subType}" \n payload: "${escapePayload(ob.payload)}"\n }`,
173
+ ).join(',') +
174
+ ']';
175
+ const oneObject2Query = ob => `{\n type: "${ob.type}" \n subType: "${ob.subType}" \n payload: "${escapePayload(ob.payload)}"}`;
176
+ const blocksSpec2Query =
177
+ bSpec =>
178
+ '[\n' +
179
+ bSpec.map(
180
+ b =>
181
+ ` {\n bs: ${oneObject2Query(b.bs)}, \n bg: ${object2Query(b.bg)}, \n os: ${object2Query(b.os)}, \n is: ${object2Query(b.is)}, \n items: ${object2Query(b.items)}}\n`) +
182
+ ']';
183
+
184
+ module.exports = {
185
+ tokenizeString,
186
+ tsvToInputBlock,
187
+ tsvHeadingTags,
188
+ treeToInputBlock,
189
+ blocksSpec2Query,
190
+ object2Query,
191
+ oneObject2Query,
192
+ };
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" ?>
2
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
+
4
+ <xsl:output method="text"/>
5
+
6
+ <xsl:template match="/">
7
+ <xsl:for-each select="/*/*">
8
+ <xsl:value-of select="normalize-space(substring-before(@n, '|'))"/>
9
+ <xsl:text>&#x09;</xsl:text>
10
+ <xsl:value-of select="normalize-space(substring-after(@n, '|'))"/>
11
+ <xsl:text>&#x09;</xsl:text>
12
+ <xsl:value-of select="normalize-space(*[2])"/>
13
+ <xsl:text>&#x09;</xsl:text>
14
+ <xsl:value-of select="normalize-space(*[3])"/>
15
+ <xsl:text>&#x0A;</xsl:text>
16
+ </xsl:for-each>
17
+ </xsl:template>
18
+
19
+ </xsl:stylesheet>
@@ -0,0 +1,85 @@
1
+ const fse = require('fs-extra');
2
+ const { tokenizeString } = require('./blocksSpec.cjs');
3
+
4
+ const itemTokens = str => tokenizeString(str).map(tr => ({
5
+ type: 'token',
6
+ subType: tr[1],
7
+ payload: tr[0],
8
+ }));
9
+
10
+ const rowRecord = rowArray => ({
11
+ 'bs': {
12
+ 'type': 'scope',
13
+ 'subType': 'start',
14
+ 'payload': `kvPrimary/${rowArray[0]}`,
15
+ },
16
+ 'bg': [],
17
+ 'os': [],
18
+ 'is': [
19
+ {
20
+ 'type': 'scope',
21
+ 'subType': 'start',
22
+ 'payload': `kvSecondary/strong/${rowArray[1]}`,
23
+ },
24
+ {
25
+ 'type': 'scope',
26
+ 'subType': 'start',
27
+ 'payload': 'kvField/briefDef',
28
+ },
29
+ {
30
+ 'type': 'scope',
31
+ 'subType': 'start',
32
+ 'payload': 'kvField/fullDef',
33
+ },
34
+ ],
35
+ 'items': [
36
+ {
37
+ 'type': 'scope',
38
+ 'subType': 'start',
39
+ 'payload': `kvSecondary/strong/${rowArray[1]}`,
40
+ },
41
+ {
42
+ 'type': 'scope',
43
+ 'subType': 'start',
44
+ 'payload': 'kvField/briefDef',
45
+ },
46
+ ...itemTokens(rowArray[2]),
47
+ {
48
+ 'type': 'scope',
49
+ 'subType': 'end',
50
+ 'payload': 'kvField/briefDef',
51
+ },
52
+ {
53
+ 'type': 'scope',
54
+ 'subType': 'start',
55
+ 'payload': 'kvField/fullDef',
56
+ },
57
+ ...itemTokens(rowArray[3]),
58
+ {
59
+ 'type': 'scope',
60
+ 'subType': 'end',
61
+ 'payload': 'kvField/fullDef',
62
+ },
63
+ {
64
+ 'type': 'scope',
65
+ 'subType': 'end',
66
+ 'payload': `kvSecondary/strong/${rowArray[1]}`,
67
+ },
68
+ ],
69
+ });
70
+
71
+ const lexicon_tsv = fse.readFileSync(process.argv[2])
72
+ .toString()
73
+ .split('\n')
74
+ .map(row => row.split('\t'))
75
+ .filter(row => row.length > 1);
76
+
77
+ console.log(
78
+ JSON.stringify(
79
+ lexicon_tsv.map(
80
+ row => rowRecord(row),
81
+ ),
82
+ null,
83
+ 2,
84
+ ),
85
+ );
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" ?>
2
+ <xsl:stylesheet
3
+ version="1.0"
4
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
+ xmlns:os="http://openscriptures.github.com/morphhb/namespace">
6
+
7
+ <xsl:output method="text"/>
8
+
9
+ <xsl:template match="/os:lexicon">
10
+ <xsl:for-each select="os:entry">
11
+ <xsl:value-of select="os:w/text()"/>
12
+ <xsl:text>&#x09;</xsl:text>
13
+ <xsl:value-of select="@id"/>
14
+ <xsl:text>&#x09;</xsl:text>
15
+ <xsl:value-of select="os:w/@pos"/>
16
+ <xsl:text>&#x09;</xsl:text>
17
+ <xsl:value-of select="os:meaning"/>
18
+ <xsl:text>&#x09;</xsl:text>
19
+ <xsl:for-each select="os:meaning/os:def">
20
+ <xsl:value-of select="concat(./text(), '; .cjs')"/>
21
+ </xsl:for-each>
22
+ <xsl:text>&#x09;</xsl:text>
23
+ <xsl:value-of select="os:usage/text()"/>
24
+ <xsl:text>&#x0A;</xsl:text>
25
+ </xsl:for-each>
26
+ </xsl:template>
27
+
28
+ </xsl:stylesheet>