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.
- package/.eslintrc.json +79 -0
- package/.gitattributes +2 -0
- package/docs/_config.yml +1 -0
- package/docs/index.md +3 -0
- package/docs/pk_edit_0_9.odt +0 -0
- package/docs/pk_edit_0_9.pdf +0 -0
- package/docs/proskomma_101_slideshow.odp +0 -0
- package/docs/proskomma_101_slideshow.pdf +0 -0
- package/docs/proskomma_edit_html.png +0 -0
- package/docs/proskomma_edit_html.svg +451 -0
- package/docs/proskomma_edit_reference.png +0 -0
- package/docs/proskomma_edit_reference.svg +349 -0
- package/docs/repo_logo.png +0 -0
- package/esm/package.json +3 -0
- package/esm/wrapper.mjs +5 -0
- package/index.cjs +6 -0
- package/package.json +18 -15
- package/src/graph/index.cjs +201 -0
- package/src/graph/lib/do_cv.cjs +249 -0
- package/src/graph/lib/dump.cjs +40 -0
- package/src/graph/lib/remake_blocks.cjs +57 -0
- package/src/graph/lib/sequence_chars.cjs +84 -0
- package/src/graph/lib/sort.cjs +39 -0
- package/src/graph/lib/tribos.cjs +97 -0
- package/src/graph/lib/tribos_expression.cjs +556 -0
- package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
- package/src/graph/lib/tribos_step.cjs +434 -0
- package/src/graph/mutations/add.cjs +91 -0
- package/src/graph/mutations/delete.cjs +61 -0
- package/src/graph/mutations/index.cjs +54 -0
- package/src/graph/mutations/rehash.cjs +17 -0
- package/src/graph/mutations/tags.cjs +120 -0
- package/src/graph/mutations/update.cjs +210 -0
- package/src/graph/mutations/versification.cjs +96 -0
- package/src/graph/queries/block.cjs +228 -0
- package/src/graph/queries/cIndex.cjs +87 -0
- package/src/graph/queries/cell.cjs +42 -0
- package/src/graph/queries/cv.cjs +19 -0
- package/src/graph/queries/cvBook.cjs +16 -0
- package/src/graph/queries/cvChapter.cjs +16 -0
- package/src/graph/queries/cvIndex.cjs +47 -0
- package/src/graph/queries/cvNavigation.cjs +116 -0
- package/src/graph/queries/cvVerseElement.cjs +84 -0
- package/src/graph/queries/cvVerses.cjs +14 -0
- package/src/graph/queries/doc_set.cjs +220 -0
- package/src/graph/queries/document.cjs +555 -0
- package/src/graph/queries/idParts.cjs +30 -0
- package/src/graph/queries/index.cjs +151 -0
- package/src/graph/queries/inputBlockSpec.cjs +17 -0
- package/src/graph/queries/inputItemObject.cjs +12 -0
- package/src/graph/queries/input_att_spec.cjs +14 -0
- package/src/graph/queries/input_key_matches.cjs +11 -0
- package/src/graph/queries/input_key_value.cjs +11 -0
- package/src/graph/queries/input_key_values.cjs +11 -0
- package/src/graph/queries/input_selector_spec.cjs +19 -0
- package/src/graph/queries/item.cjs +71 -0
- package/src/graph/queries/itemGroup.cjs +75 -0
- package/src/graph/queries/key_value.cjs +18 -0
- package/src/graph/queries/kv_entry.cjs +21 -0
- package/src/graph/queries/kv_sequence.cjs +151 -0
- package/src/graph/queries/node.cjs +44 -0
- package/src/graph/queries/orig.cjs +11 -0
- package/src/graph/queries/regex_index.cjs +18 -0
- package/src/graph/queries/row_equals_spec.cjs +11 -0
- package/src/graph/queries/row_match_spec.cjs +11 -0
- package/src/graph/queries/selector_spec.cjs +29 -0
- package/src/graph/queries/sequence.cjs +314 -0
- package/src/graph/queries/table_sequence.cjs +192 -0
- package/src/graph/queries/tree_sequence.cjs +58 -0
- package/src/graph/queries/verseNumber.cjs +44 -0
- package/src/graph/queries/verseRange.cjs +11 -0
- package/src/graph/queries/versification.cjs +25 -0
- package/src/index.cjs +583 -0
- package/src/model/doc_set.cjs +389 -0
- package/src/model/doc_set_helpers/block.cjs +232 -0
- package/src/model/doc_set_helpers/enum.cjs +87 -0
- package/src/model/doc_set_helpers/item.cjs +198 -0
- package/src/model/doc_set_helpers/rehash.cjs +53 -0
- package/src/model/doc_set_helpers/selectors.cjs +58 -0
- package/src/model/doc_set_helpers/serialize.cjs +22 -0
- package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
- package/src/model/doc_set_helpers/update.cjs +290 -0
- package/src/model/document.cjs +369 -0
- package/src/model/document_helpers/blocks.cjs +135 -0
- package/src/model/document_helpers/chapter_verse.cjs +291 -0
- package/src/model/document_helpers/pre_enums.cjs +67 -0
- package/src/model/document_helpers/sequences.cjs +205 -0
- package/src/model/document_helpers/serialize_succinct.cjs +55 -0
- package/src/model/document_helpers/succinct_filter.cjs +102 -0
- package/src/model/versifications/eng_vrs.cjs +455 -0
- package/src/model/versifications/index.cjs +38 -0
- package/src/model/versifications/lxx_vrs.cjs +950 -0
- package/src/model/versifications/org_vrs.cjs +155 -0
- package/src/model/versifications/rsc_vrs.cjs +342 -0
- package/src/model/versifications/rso_vrs.cjs +541 -0
- package/src/model/versifications/vul_vrs.cjs +835 -0
- package/src/parser/index.cjs +506 -0
- package/src/parser/lexers/index.cjs +11 -0
- package/src/parser/lexers/lexingRegexes.cjs +45 -0
- package/src/parser/lexers/nodes.cjs +123 -0
- package/src/parser/lexers/object_for_fragment.cjs +123 -0
- package/src/parser/lexers/tsv.cjs +45 -0
- package/src/parser/lexers/usfm.cjs +17 -0
- package/src/parser/lexers/usx/index.cjs +7 -0
- package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
- package/src/parser/lib/tokenize.cjs +37 -0
- package/src/parser/model/index.cjs +637 -0
- package/src/parser/parser_specs.cjs +781 -0
- package/src/pipelines/perf2x/index.cjs +7 -0
- package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
- package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
- package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
- package/src/transforms/index.cjs +9 -0
- package/src/transforms/perf2PkJson.cjs +534 -0
- package/src/transforms/perf2usfm.cjs +294 -0
- package/src/util/byteArray.cjs +251 -0
- package/src/util/canons.cjs +117 -0
- package/src/util/enums.cjs +41 -0
- package/src/util/generateId.cjs +6 -0
- package/src/util/graftDefs.cjs +15 -0
- package/src/util/index.cjs +29 -0
- package/src/util/inspectSuccinct.cjs +59 -0
- package/src/util/itemDefs.cjs +33 -0
- package/src/util/parserConstantDefs.cjs +30 -0
- package/src/util/scopeDefs.cjs +173 -0
- package/src/util/scriptlike/blocksSpec.cjs +192 -0
- package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
- package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
- package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
- package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
- package/src/util/succinct.cjs +159 -0
- package/src/util/tags.cjs +28 -0
- package/src/util/tokenDefs.cjs +27 -0
- package/src/util/versification.cjs +364 -0
- package/dist/index.js +0 -8
- package/dist/index.js.LICENSE.txt +0 -23
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const utils = require('../../util/index.cjs');
|
|
2
|
+
|
|
3
|
+
const tagMutationsSchemaString = `
|
|
4
|
+
"""Add one or more tags to a docSet, if they are not already present"""
|
|
5
|
+
addDocSetTags(
|
|
6
|
+
"""The id of the docSet to which the tags will be added"""
|
|
7
|
+
docSetId: String!
|
|
8
|
+
"""A list of tags to be added"""
|
|
9
|
+
tags: [String]!
|
|
10
|
+
): [String!]!
|
|
11
|
+
"""Add one or more tags to a document, if they are not already present"""
|
|
12
|
+
addDocumentTags(
|
|
13
|
+
"""The id of the docSet containing the document to which the tags will be added"""
|
|
14
|
+
docSetId: String!
|
|
15
|
+
"""The id of the document to which the tags will be added"""
|
|
16
|
+
documentId: String!
|
|
17
|
+
"""A list of tags to be added"""
|
|
18
|
+
tags: [String]!
|
|
19
|
+
): [String!]
|
|
20
|
+
"""Add one or more tags to a sequence, if they are not already present"""
|
|
21
|
+
addSequenceTags(
|
|
22
|
+
"""The id of the docSet containing the document containing the sequence to which the tags will be added"""
|
|
23
|
+
docSetId: String!
|
|
24
|
+
"""The id of the document containing the sequence to which the tags will be added"""
|
|
25
|
+
documentId: String!
|
|
26
|
+
"""The id of the sequence to which the tags will be added"""
|
|
27
|
+
sequenceId: String!
|
|
28
|
+
"""A list of tags to be added"""
|
|
29
|
+
tags: [String]!
|
|
30
|
+
) : [String!]
|
|
31
|
+
"""Remove one or more tags from a docSet, if they are present"""
|
|
32
|
+
removeDocSetTags(
|
|
33
|
+
"""The id of the docSet from which the tags will be removed"""
|
|
34
|
+
docSetId: String!
|
|
35
|
+
"""A list of tags to be removed"""
|
|
36
|
+
tags: [String]!
|
|
37
|
+
): [String!]
|
|
38
|
+
"""Remove one or more tags from a document, if they are present"""
|
|
39
|
+
removeDocumentTags(
|
|
40
|
+
"""The id of the docSet containing the document from which the tags will be removed"""
|
|
41
|
+
docSetId: String!
|
|
42
|
+
"""The id of the document from which the tags will be removed"""
|
|
43
|
+
documentId: String!
|
|
44
|
+
"""A list of tags to be removed"""
|
|
45
|
+
tags: [String]!
|
|
46
|
+
): [String!]
|
|
47
|
+
"""Remove one or more tags from a sequence, if they are present"""
|
|
48
|
+
removeSequenceTags(
|
|
49
|
+
"""The id of the docSet containing the document containing the sequence from which the tags will be removed"""
|
|
50
|
+
docSetId: String!
|
|
51
|
+
"""The id of the document containing the sequence from which the tags will be removed"""
|
|
52
|
+
documentId: String!
|
|
53
|
+
"""The id of the sequence from which the tags will be removed"""
|
|
54
|
+
sequenceId: String!
|
|
55
|
+
"""A list of tags to be removed"""
|
|
56
|
+
tags: [String]!
|
|
57
|
+
) : [String!]
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
const tagMutationsResolvers = {
|
|
61
|
+
addDocSetTags: (root, args) => {
|
|
62
|
+
const docSet = root.docSets[args.docSetId];
|
|
63
|
+
|
|
64
|
+
for (const tag of args.tags) {
|
|
65
|
+
docSet.addTag(tag);
|
|
66
|
+
}
|
|
67
|
+
return Array.from(docSet.tags);
|
|
68
|
+
},
|
|
69
|
+
addDocumentTags: (root, args) => {
|
|
70
|
+
const docSet = root.docSets[args.docSetId];
|
|
71
|
+
const document = docSet.processor.documents[args.documentId];
|
|
72
|
+
|
|
73
|
+
for (const tag of args.tags) {
|
|
74
|
+
document.addTag(tag);
|
|
75
|
+
}
|
|
76
|
+
return Array.from(document.tags);
|
|
77
|
+
},
|
|
78
|
+
addSequenceTags: (root, args) => {
|
|
79
|
+
const docSet = root.docSets[args.docSetId];
|
|
80
|
+
const document = docSet.processor.documents[args.documentId];
|
|
81
|
+
const sequence = document.sequences[args.sequenceId];
|
|
82
|
+
|
|
83
|
+
for (const tag of args.tags) {
|
|
84
|
+
utils.tags.addTag(sequence.tags, tag);
|
|
85
|
+
}
|
|
86
|
+
return Array.from(sequence.tags);
|
|
87
|
+
},
|
|
88
|
+
removeDocSetTags: (root, args) => {
|
|
89
|
+
const docSet = root.docSets[args.docSetId];
|
|
90
|
+
|
|
91
|
+
for (const tag of args.tags) {
|
|
92
|
+
docSet.removeTag(tag);
|
|
93
|
+
}
|
|
94
|
+
return Array.from(docSet.tags);
|
|
95
|
+
},
|
|
96
|
+
removeDocumentTags: (root, args) => {
|
|
97
|
+
const docSet = root.docSets[args.docSetId];
|
|
98
|
+
const document = docSet.processor.documents[args.documentId];
|
|
99
|
+
|
|
100
|
+
for (const tag of args.tags) {
|
|
101
|
+
document.removeTag(tag);
|
|
102
|
+
}
|
|
103
|
+
return Array.from(document.tags);
|
|
104
|
+
},
|
|
105
|
+
removeSequenceTags: (root, args) => {
|
|
106
|
+
const docSet = root.docSets[args.docSetId];
|
|
107
|
+
const document = docSet.processor.documents[args.documentId];
|
|
108
|
+
const sequence = document.sequences[args.sequenceId];
|
|
109
|
+
|
|
110
|
+
for (const tag of args.tags) {
|
|
111
|
+
utils.tags.removeTag(sequence.tags, tag);
|
|
112
|
+
}
|
|
113
|
+
return Array.from(sequence.tags);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
tagMutationsSchemaString,
|
|
119
|
+
tagMutationsResolvers,
|
|
120
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const { PipelineHandler } = require('proskomma-json-tools');
|
|
2
|
+
const { remakeBlocks } = require('../lib/remake_blocks.cjs');
|
|
3
|
+
const pipelines = require('../../pipelines/perf2x/index.cjs');
|
|
4
|
+
const customTransforms = require('../../transforms/index.cjs');
|
|
5
|
+
|
|
6
|
+
const updateMutationsSchemaString = `
|
|
7
|
+
"""Replaces the items of a block with a new set of items"""
|
|
8
|
+
updateItems(
|
|
9
|
+
"""The id of the docSet containing the document containing the sequence containing the block for which the items will be updated"""
|
|
10
|
+
docSetId: String!
|
|
11
|
+
"""The id of the document containing the sequence containing the block for which the items will be updated"""
|
|
12
|
+
documentId: String!
|
|
13
|
+
"""The id of the sequence containing the block for which the items will be updated (defaults to the main sequence)"""
|
|
14
|
+
sequenceId: String
|
|
15
|
+
"""The zero-indexed number of the block for which the items will be updated"""
|
|
16
|
+
blockPosition: Int!
|
|
17
|
+
"""The new content for the block as item objects"""
|
|
18
|
+
items: [InputItemObject!]
|
|
19
|
+
"""BlockGrafts for the block as item objects"""
|
|
20
|
+
blockGrafts: [InputItemObject!]
|
|
21
|
+
"""Optional blockScope for the block as an item object"""
|
|
22
|
+
blockScope: InputItemObject
|
|
23
|
+
): Boolean!
|
|
24
|
+
"""Replaces all the blocks of a sequence with a new set of blocks"""
|
|
25
|
+
updateAllBlocks(
|
|
26
|
+
"""The id of the docSet containing the document containing the sequence for which the blocks will be updated"""
|
|
27
|
+
docSetId: String!
|
|
28
|
+
"""The id of the document containing the sequence for which the blocks will be updated"""
|
|
29
|
+
documentId: String!
|
|
30
|
+
"""The id of the sequence for which the blocks will be updated (defaults to the main sequence)"""
|
|
31
|
+
sequenceId: String
|
|
32
|
+
"""The JSON describing blocks"""
|
|
33
|
+
blocksSpec: [inputBlockSpec!]!
|
|
34
|
+
): Boolean!
|
|
35
|
+
"""Replaces all the blocks of a sequence with a new set of blocks derived from PERF"""
|
|
36
|
+
updateSequenceFromPerf(
|
|
37
|
+
"""The id of the docSet containing the document containing the sequence for which the blocks will be updated"""
|
|
38
|
+
docSetId: String!
|
|
39
|
+
"""The id of the document containing the sequence for which the blocks will be updated"""
|
|
40
|
+
documentId: String!
|
|
41
|
+
"""The id of the sequence for which the blocks will be updated (defaults to the main sequence)"""
|
|
42
|
+
sequenceId: String
|
|
43
|
+
"""The JSON describing blocks"""
|
|
44
|
+
perf: String!
|
|
45
|
+
): Boolean!
|
|
46
|
+
"""Garbage collects unused sequences within a document. (You probably don\\'t need to do this.)"""
|
|
47
|
+
gcSequences(
|
|
48
|
+
"""The id of the docSet containing the document to be garbage collected"""
|
|
49
|
+
docSetId: String!
|
|
50
|
+
"""The id of the document to be garbage collected"""
|
|
51
|
+
documentId: String!
|
|
52
|
+
) : Boolean!
|
|
53
|
+
|
|
54
|
+
`;
|
|
55
|
+
const updateMutationsResolvers = {
|
|
56
|
+
updateItems: (root, args) => {
|
|
57
|
+
const docSet = root.docSets[args.docSetId];
|
|
58
|
+
|
|
59
|
+
if (!docSet) {
|
|
60
|
+
throw new Error(`DocSet '${args.docSetId}' not found`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!args.items) {
|
|
64
|
+
throw new Error('Must provide items');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const itemsResult = docSet.updateItems(
|
|
68
|
+
args.documentId,
|
|
69
|
+
args.sequenceId,
|
|
70
|
+
args.blockPosition,
|
|
71
|
+
args.items,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (!itemsResult) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (args.blockGrafts) {
|
|
79
|
+
const bgResult = docSet.updateBlockGrafts(
|
|
80
|
+
args.documentId,
|
|
81
|
+
args.sequenceId,
|
|
82
|
+
args.blockPosition,
|
|
83
|
+
args.blockGrafts,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (!bgResult) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (args.blockScope) {
|
|
92
|
+
const bsResult = docSet.updateBlockScope(
|
|
93
|
+
args.documentId,
|
|
94
|
+
args.sequenceId,
|
|
95
|
+
args.blockPosition,
|
|
96
|
+
args.blockScope,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!bsResult) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
},
|
|
105
|
+
updateAllBlocks: (root, args) => {
|
|
106
|
+
const docSet = root.docSets[args.docSetId];
|
|
107
|
+
|
|
108
|
+
if (!docSet) {
|
|
109
|
+
throw new Error(`DocSet '${args.docSetId}' not found`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const document = root.documents[args.documentId];
|
|
113
|
+
|
|
114
|
+
if (!document) {
|
|
115
|
+
throw new Error(`Document '${args.documentId}' not found`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const sequence = document.sequences[args.sequenceId || document.mainId];
|
|
119
|
+
|
|
120
|
+
if (!sequence) {
|
|
121
|
+
throw new Error(`Sequence '${args.sequenceId || document.mainId}' not found`);
|
|
122
|
+
}
|
|
123
|
+
remakeBlocks(docSet, document, sequence, args.blocksSpec);
|
|
124
|
+
document.buildChapterVerseIndex();
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
updateSequenceFromPerf: async (root, args) => {
|
|
128
|
+
const docSet = root.docSets[args.docSetId];
|
|
129
|
+
|
|
130
|
+
if (!docSet) {
|
|
131
|
+
throw new Error(`DocSet '${args.docSetId}' not found`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const document = root.documents[args.documentId];
|
|
135
|
+
|
|
136
|
+
if (!document) {
|
|
137
|
+
throw new Error(`Document '${args.documentId}' not found`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const sequence = document.sequences[args.sequenceId || document.mainId];
|
|
141
|
+
|
|
142
|
+
if (!sequence) {
|
|
143
|
+
throw new Error(`Sequence '${args.sequenceId || document.mainId}' not found`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const sequencePerf = JSON.parse(args.perf);
|
|
147
|
+
const perf = {
|
|
148
|
+
'schema': {
|
|
149
|
+
'structure': 'flat',
|
|
150
|
+
'structure_version': '0.3.0',
|
|
151
|
+
'constraints': [
|
|
152
|
+
{
|
|
153
|
+
'name': 'perf',
|
|
154
|
+
'version': '0.3.0',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
'metadata': {
|
|
159
|
+
'translation': {},
|
|
160
|
+
'document': {},
|
|
161
|
+
},
|
|
162
|
+
'sequences': {},
|
|
163
|
+
'main_sequence_id': args.sequenceId,
|
|
164
|
+
};
|
|
165
|
+
perf.sequences[args.sequenceId] = sequencePerf;
|
|
166
|
+
|
|
167
|
+
let blocksSpec = {};
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const pipelineHandler = new PipelineHandler({
|
|
171
|
+
pipelines:pipelines,
|
|
172
|
+
transforms:customTransforms,
|
|
173
|
+
proskomma:root,
|
|
174
|
+
});
|
|
175
|
+
const output = await pipelineHandler.runPipeline('perf2PkJsonPipeline', { perf });
|
|
176
|
+
blocksSpec = Object.values(output.pkJson)[0];
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.error('pipelineHandler Error :\n', err);
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
remakeBlocks(docSet, document, sequence, blocksSpec);
|
|
182
|
+
document.buildChapterVerseIndex();
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
gcSequences: (root, args) => {
|
|
186
|
+
const docSet = root.docSets[args.docSetId];
|
|
187
|
+
|
|
188
|
+
if (!docSet) {
|
|
189
|
+
throw new Error(`DocSet '${args.docSetId}' not found`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const document = root.documents[args.documentId];
|
|
193
|
+
|
|
194
|
+
if (!document) {
|
|
195
|
+
throw new Error(`Document '${args.documentId}' not found`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (document.gcSequences()) {
|
|
199
|
+
docSet.rehash();
|
|
200
|
+
return true;
|
|
201
|
+
} else {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
module.exports = {
|
|
208
|
+
updateMutationsSchemaString,
|
|
209
|
+
updateMutationsResolvers,
|
|
210
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const utils = require('../../util/index.cjs');
|
|
2
|
+
|
|
3
|
+
const versificationMutationsSchemaString = `
|
|
4
|
+
"""Adds verse mapping tables to the documents in a docSet, where the verse mapping may be provided in legacy .vrs or JSON format"""
|
|
5
|
+
setVerseMapping(
|
|
6
|
+
"""the id of the docSet to which the verse mapping will be added"""
|
|
7
|
+
docSetId: String!
|
|
8
|
+
"""The verse mapping, in legacy .vrs format (as a string)"""
|
|
9
|
+
vrsSource: String
|
|
10
|
+
"""The verse mapping, in JSON format (as a string)"""
|
|
11
|
+
jsonSource: String
|
|
12
|
+
): Boolean!
|
|
13
|
+
"""Removes verse mapping tables from the documents in a docSet"""
|
|
14
|
+
unsetVerseMapping(
|
|
15
|
+
"""The id of the docSet from which verse mapping will be removed"""
|
|
16
|
+
docSetId: String!
|
|
17
|
+
): Boolean!
|
|
18
|
+
`;
|
|
19
|
+
const versificationMutationsResolvers = {
|
|
20
|
+
setVerseMapping: (root, args) => {
|
|
21
|
+
if (args.vrsSource && args.jsonSource) {
|
|
22
|
+
throw new Error('Cannot specify both vrsSource and jsonSource');
|
|
23
|
+
} else if (!args.vrsSource && !args.jsonSource) {
|
|
24
|
+
throw new Error('Must specify either vrsSource or jsonSource');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const docSet = root.docSets[args.docSetId];
|
|
28
|
+
|
|
29
|
+
if (!docSet) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let jsonSource;
|
|
34
|
+
|
|
35
|
+
if (args.vrsSource) {
|
|
36
|
+
jsonSource = utils.versification.vrs2json(args.vrsSource);
|
|
37
|
+
} else {
|
|
38
|
+
jsonSource = args.jsonSource;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const forwardSuccinctTree = utils.versification.succinctifyVerseMappings(
|
|
42
|
+
jsonSource.mappedVerses,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const reversedJsonSource = utils.versification.reverseVersification(jsonSource);
|
|
46
|
+
const reversedSuccinctTree = utils.versification.succinctifyVerseMappings(
|
|
47
|
+
reversedJsonSource.reverseMappedVerses,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
for (const document of docSet.documents().filter(doc => 'bookCode' in doc.headers)) {
|
|
51
|
+
const bookCode = document.headers['bookCode'];
|
|
52
|
+
const bookDocument = docSet.documentWithBook(bookCode);
|
|
53
|
+
|
|
54
|
+
if (!bookDocument) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const bookMainSequence = bookDocument.sequences[bookDocument.mainId];
|
|
59
|
+
bookMainSequence.verseMapping = {};
|
|
60
|
+
|
|
61
|
+
if (bookCode in forwardSuccinctTree) {
|
|
62
|
+
bookMainSequence.verseMapping.forward = forwardSuccinctTree[bookCode];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (bookCode in reversedSuccinctTree) {
|
|
66
|
+
bookMainSequence.verseMapping.reversed = reversedSuccinctTree[bookCode];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
docSet.tags.add('hasMapping');
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
unsetVerseMapping: (root, args) => {
|
|
73
|
+
const docSet = root.docSets[args.docSetId];
|
|
74
|
+
|
|
75
|
+
if (!docSet) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const document of docSet.documents().filter(doc => 'bookCode' in doc.headers)) {
|
|
80
|
+
const bookCode = document.headers['bookCode'];
|
|
81
|
+
const bookDocument = docSet.documentWithBook(bookCode);
|
|
82
|
+
|
|
83
|
+
if (bookDocument) {
|
|
84
|
+
const bookMainSequence = bookDocument.sequences[bookDocument.mainId];
|
|
85
|
+
bookMainSequence.verseMapping = {};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
docSet.tags.delete('hasMapping');
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
versificationMutationsSchemaString,
|
|
95
|
+
versificationMutationsResolvers,
|
|
96
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const xre = require('xregexp');
|
|
2
|
+
const utils = require('../../util/index.cjs');
|
|
3
|
+
const { dumpBlock } = require('../lib/dump.cjs');
|
|
4
|
+
|
|
5
|
+
const scopeMatchesStartsWith = (sw, s) => {
|
|
6
|
+
if (sw.length === 0) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
for (const swv of sw) {
|
|
11
|
+
if (s.startsWith(swv)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const blockSchemaString = `
|
|
19
|
+
"""Part of a sequence, roughly equivalent to a USFM paragraph"""
|
|
20
|
+
type Block {
|
|
21
|
+
"""The length in bytes of the succinct representation of c (block items)"""
|
|
22
|
+
cBL: Int!
|
|
23
|
+
"""The length in bytes of the succinct representation of bg (block grafts)"""
|
|
24
|
+
bgBL: Int!
|
|
25
|
+
"""The length in bytes of the succinct representation of os (open scopes)"""
|
|
26
|
+
osBL: Int!
|
|
27
|
+
"""The length in bytes of the succinct representation of is (included scopes)"""
|
|
28
|
+
isBL: Int!
|
|
29
|
+
"""The length in bytes of the succinct representation of nt (nextToken at the start of the block)"""
|
|
30
|
+
ntBL: Int!
|
|
31
|
+
"""The number of items in the succinct representation of c (block items)"""
|
|
32
|
+
cL: Int!
|
|
33
|
+
"""The number of items in the succinct representation of bg (block grafts)"""
|
|
34
|
+
bgL: Int!
|
|
35
|
+
"""The number of items in the succinct representation of os (open scopes)"""
|
|
36
|
+
osL: Int!
|
|
37
|
+
"""The number of items in the succinct representation of is (included scopes)"""
|
|
38
|
+
isL: Int!
|
|
39
|
+
"""A list of included scopes for this block"""
|
|
40
|
+
is: [Item!]!
|
|
41
|
+
"""A list of open scopes for this block"""
|
|
42
|
+
os: [Item!]!
|
|
43
|
+
"""The block scope for this block"""
|
|
44
|
+
bs: Item!
|
|
45
|
+
"""A list of block grafts for this block"""
|
|
46
|
+
bg: [Item!]!
|
|
47
|
+
"""The value of nextToken at the start of this block"""
|
|
48
|
+
nt: Int!
|
|
49
|
+
"""A list of items from the c (content) field of the block"""
|
|
50
|
+
items(
|
|
51
|
+
"""Only return items that are within specific scopes"""
|
|
52
|
+
withScopes: [String!]
|
|
53
|
+
"""If true, withScopes filtering matches items within at least one of the specified scopes"""
|
|
54
|
+
anyScope: Boolean
|
|
55
|
+
"""Only return items that are within a chapterVerse range (ch or ch:v or ch:v-v or ch:v-ch:v)"""
|
|
56
|
+
withScriptureCV: String
|
|
57
|
+
"""If true, adds scope and nextToken information to each token"""
|
|
58
|
+
includeContext: Boolean
|
|
59
|
+
) : [Item!]!
|
|
60
|
+
"""A list of tokens from the c (content) field of the block"""
|
|
61
|
+
tokens(
|
|
62
|
+
"""Only return tokens that are within specific scopes"""
|
|
63
|
+
withScopes: [String!]
|
|
64
|
+
"""If true, withScopes filtering matches tokens within at least one of the specified scopes"""
|
|
65
|
+
anyScope: Boolean
|
|
66
|
+
"""Only return tokens that are within a chapterVerse range (ch or ch:v or ch:v-v or ch:v-ch:v)"""
|
|
67
|
+
withScriptureCV: String
|
|
68
|
+
"""If true, adds scope and nextToken information to each token"""
|
|
69
|
+
includeContext: Boolean
|
|
70
|
+
"""Return tokens whose payload is an exact match to one of the specified strings"""
|
|
71
|
+
withChars: [String!]
|
|
72
|
+
"""Return tokens whose payload matches one of the specified regexes"""
|
|
73
|
+
withMatchingChars: [String!]
|
|
74
|
+
"""Return tokens with one of the specified subTypes"""
|
|
75
|
+
withSubTypes: [String!]
|
|
76
|
+
) : [Item!]!
|
|
77
|
+
"""The text of the block as a single string"""
|
|
78
|
+
text(
|
|
79
|
+
"""Only return text that is within a chapterVerse range (ch or ch:v or ch:v-v or ch:v-ch:v)"""
|
|
80
|
+
withScriptureCV: String
|
|
81
|
+
"""If true, converts each whitespace character to a single space"""
|
|
82
|
+
normalizeSpace: Boolean
|
|
83
|
+
): String!
|
|
84
|
+
"""'Block items grouped by scopes or milestones"""
|
|
85
|
+
itemGroups(
|
|
86
|
+
"""Produce one itemGroup for every match of the list of scopes"""
|
|
87
|
+
byScopes: [String!]
|
|
88
|
+
"""Start a new itemGroup whenever a milestone in the list is encountered"""
|
|
89
|
+
byMilestones: [String!]
|
|
90
|
+
): [ItemGroup]!
|
|
91
|
+
"""The block content as a string in a compact eyeballable format"""
|
|
92
|
+
dump: String!
|
|
93
|
+
"""A list of the labels for the block\\'s bs, os and is scopes"""
|
|
94
|
+
scopeLabels(
|
|
95
|
+
"""Only include scopes that begin with this value"""
|
|
96
|
+
startsWith: [String!]
|
|
97
|
+
): [String!]!
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
const blockResolvers = {
|
|
102
|
+
cBL: root => root.c.length,
|
|
103
|
+
bgBL: root => root.bg.length,
|
|
104
|
+
osBL: root => root.os.length,
|
|
105
|
+
isBL: root => root.is.length,
|
|
106
|
+
ntBL: root => root.nt.length,
|
|
107
|
+
cL: (root, args, context) => context.docSet.countItems(root.c),
|
|
108
|
+
bgL: (root, args, context) => context.docSet.countItems(root.bg),
|
|
109
|
+
osL: (root, args, context) => context.docSet.countItems(root.os),
|
|
110
|
+
isL: (root, args, context) => context.docSet.countItems(root.is),
|
|
111
|
+
is: (root, args, context) => context.docSet.unsuccinctifyScopes(root.is),
|
|
112
|
+
os: (root, args, context) => context.docSet.unsuccinctifyScopes(root.os),
|
|
113
|
+
bs: (root, args, context) => {
|
|
114
|
+
// eslint-disable-next-line no-unused-vars
|
|
115
|
+
const [itemLength, itemType, itemSubtype] = utils.succinct.headerBytes(root.bs, 0);
|
|
116
|
+
return context.docSet.unsuccinctifyScope(root.bs, itemType, itemSubtype, 0);
|
|
117
|
+
},
|
|
118
|
+
bg: (root, args, context) => context.docSet.unsuccinctifyGrafts(root.bg),
|
|
119
|
+
nt: root => root.nt.nByte(0),
|
|
120
|
+
items:
|
|
121
|
+
(root, args, context) => {
|
|
122
|
+
if (args.withScopes && args.withScriptureCV) {
|
|
123
|
+
throw new Error('Cannot specify both withScopes and withScriptureCV');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (args.withScriptureCV) {
|
|
127
|
+
return context.docSet.unsuccinctifyItemsWithScriptureCV(root, args.withScriptureCV, {}, args.includeContext || false);
|
|
128
|
+
} else {
|
|
129
|
+
return context.docSet.unsuccinctifyPrunedItems(
|
|
130
|
+
root,
|
|
131
|
+
{
|
|
132
|
+
tokens: true,
|
|
133
|
+
scopes: true,
|
|
134
|
+
grafts: true,
|
|
135
|
+
requiredScopes: args.withScopes || [],
|
|
136
|
+
anyScope: args.anyScope || false,
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
tokens:
|
|
142
|
+
(root, args, context) => {
|
|
143
|
+
if (Object.keys(args).filter(a => a.includes('Chars')).length > 1) {
|
|
144
|
+
throw new Error('Only one of "withChars", "withAnyCaseChars" and "withCharsMatchingRegex" may be specified');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let ret;
|
|
148
|
+
|
|
149
|
+
if (args.withScriptureCV) {
|
|
150
|
+
ret = context.docSet.unsuccinctifyItemsWithScriptureCV(
|
|
151
|
+
root,
|
|
152
|
+
args.withScriptureCV,
|
|
153
|
+
{ tokens: true },
|
|
154
|
+
args.includeContext || false,
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
ret = context.docSet.unsuccinctifyPrunedItems(
|
|
158
|
+
root,
|
|
159
|
+
{
|
|
160
|
+
tokens: true,
|
|
161
|
+
scopes: true,
|
|
162
|
+
requiredScopes: args.withScopes || [],
|
|
163
|
+
anyScope: args.anyScope || false,
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (args.withSubTypes) {
|
|
169
|
+
ret = ret.filter(i => args.withSubTypes.includes(i[1]));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (args.withChars) {
|
|
173
|
+
ret = ret.filter(i => args.withChars.includes(i[2]));
|
|
174
|
+
} else if (args.withMatchingChars) {
|
|
175
|
+
ret = ret.filter(i => {
|
|
176
|
+
for (const re of args.withMatchingChars) {
|
|
177
|
+
if (xre.test(i, xre(re))) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return ret.filter(i => i[0] === 'token');
|
|
186
|
+
},
|
|
187
|
+
text:
|
|
188
|
+
(root, args, context) => {
|
|
189
|
+
const tokens = args.withScriptureCV ?
|
|
190
|
+
context.docSet.unsuccinctifyItemsWithScriptureCV(
|
|
191
|
+
root,
|
|
192
|
+
args.withScriptureCV,
|
|
193
|
+
{ tokens: true },
|
|
194
|
+
false,
|
|
195
|
+
) :
|
|
196
|
+
context.docSet.unsuccinctifyItems(root.c, { tokens: true }, null);
|
|
197
|
+
let ret = tokens.map(t => t[2]).join('').trim();
|
|
198
|
+
|
|
199
|
+
if (args.normalizeSpace) {
|
|
200
|
+
ret = ret.replace(/[ \t\n\r]+/g, ' ');
|
|
201
|
+
}
|
|
202
|
+
return ret;
|
|
203
|
+
},
|
|
204
|
+
itemGroups: (root, args, context) => {
|
|
205
|
+
if (args.byScopes && args.byMilestones) {
|
|
206
|
+
throw new Error('Cannot specify both byScopes and byMilestones');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!args.byScopes && !args.byMilestones) {
|
|
210
|
+
throw new Error('Must specify either byScopes or byMilestones');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (args.byScopes) {
|
|
214
|
+
return context.docSet.sequenceItemsByScopes([root], args.byScopes);
|
|
215
|
+
} else {
|
|
216
|
+
return context.docSet.sequenceItemsByMilestones([root], args.byMilestones);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
dump: (root, args, context) => dumpBlock(context.docSet.unsuccinctifyBlock(root, {}, null)),
|
|
220
|
+
scopeLabels: (root, args, context) =>
|
|
221
|
+
[...context.docSet.unsuccinctifyBlockScopeLabelsSet(root)]
|
|
222
|
+
.filter(s => !args.startsWith || scopeMatchesStartsWith(args.startsWith, s)),
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
module.exports = {
|
|
226
|
+
blockSchemaString,
|
|
227
|
+
blockResolvers,
|
|
228
|
+
};
|