proskomma-core 0.9.7 → 0.9.12
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/babel.config.js +18 -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.js +6 -0
- package/package.json +19 -17
- 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/test/code/main/bad.cjs +79 -0
- package/test/code/main/basics.cjs +534 -0
- package/test/code/main/block.cjs +586 -0
- package/test/code/main/block_scope_numbers.cjs +31 -0
- package/test/code/main/blocks_with_atts.cjs +150 -0
- package/test/code/main/blocks_with_cv.cjs +250 -0
- package/test/code/main/break.cjs +73 -0
- package/test/code/main/checksum.cjs +36 -0
- package/test/code/main/cl_global.cjs +35 -0
- package/test/code/main/class_for_fragment.cjs +18 -0
- package/test/code/main/clean_usfm.cjs +46 -0
- package/test/code/main/cp_vp.cjs +158 -0
- package/test/code/main/custom.cjs +124 -0
- package/test/code/main/cv.cjs +249 -0
- package/test/code/main/cvMatching.cjs +155 -0
- package/test/code/main/cv_indexes.cjs +189 -0
- package/test/code/main/cv_navigation.cjs +124 -0
- package/test/code/main/document.cjs +382 -0
- package/test/code/main/empty_blocks.cjs +71 -0
- package/test/code/main/entries.cjs +402 -0
- package/test/code/main/export_lexing_regexes.cjs +19 -0
- package/test/code/main/fig.cjs +67 -0
- package/test/code/main/filter.cjs +222 -0
- package/test/code/main/glossary.cjs +36 -0
- package/test/code/main/graft_headings.cjs +36 -0
- package/test/code/main/graft_introduction.cjs +96 -0
- package/test/code/main/graft_note.cjs +104 -0
- package/test/code/main/graft_rems.cjs +34 -0
- package/test/code/main/graft_sidebars.cjs +62 -0
- package/test/code/main/graft_title.cjs +36 -0
- package/test/code/main/hello.cjs +105 -0
- package/test/code/main/import_document.cjs +22 -0
- package/test/code/main/import_usfm_int.cjs +48 -0
- package/test/code/main/item_groups.cjs +133 -0
- package/test/code/main/items_with_cv.cjs +311 -0
- package/test/code/main/milestone_attributes.cjs +163 -0
- package/test/code/main/mixed_sequence_documents.cjs +137 -0
- package/test/code/main/mixed_sequences.cjs +217 -0
- package/test/code/main/modify_sequence.cjs +29 -0
- package/test/code/main/multiple_chapters.cjs +58 -0
- package/test/code/main/multiple_content.cjs +105 -0
- package/test/code/main/mutate_add.cjs +180 -0
- package/test/code/main/mutate_delete.cjs +236 -0
- package/test/code/main/mutate_rehash.cjs +68 -0
- package/test/code/main/mutate_tags.cjs +90 -0
- package/test/code/main/mutate_update.cjs +538 -0
- package/test/code/main/selectors.cjs +289 -0
- package/test/code/main/sequence.cjs +361 -0
- package/test/code/main/serialize.cjs +104 -0
- package/test/code/main/spans.cjs +51 -0
- package/test/code/main/split_long_tokens.cjs +30 -0
- package/test/code/main/standard_vrs.cjs +76 -0
- package/test/code/main/subclass.cjs +25 -0
- package/test/code/main/table.cjs +119 -0
- package/test/code/main/tags.cjs +248 -0
- package/test/code/main/token_alignment.cjs +84 -0
- package/test/code/main/trees.cjs +211 -0
- package/test/code/main/tribos.cjs +865 -0
- package/test/code/main/tsv.cjs +385 -0
- package/test/code/main/usx_ref.cjs +65 -0
- package/test/code/main/verse_mapping.cjs +252 -0
- package/test/code/main/verse_range.cjs +31 -0
- package/test/code/main/word_likes.cjs +41 -0
- package/test/code/utils/byte_array.cjs +271 -0
- package/test/code/utils/canons.cjs +20 -0
- package/test/code/utils/generate_id.cjs +17 -0
- package/test/code/utils/graft_defs.cjs +16 -0
- package/test/code/utils/inspect.cjs +130 -0
- package/test/code/utils/items.cjs +56 -0
- package/test/code/utils/push_succinct.cjs +69 -0
- package/test/code/utils/scope_defs.cjs +79 -0
- package/test/code/utils/serialize.cjs +28 -0
- package/test/code/utils/splice.cjs +67 -0
- package/test/code/utils/tags.cjs +69 -0
- package/test/code/utils/versification.cjs +249 -0
- package/test/lib/load.js +110 -0
- package/test/skipped_code/diff.js +53 -0
- package/test/test_data/inputBlockSpec/dodson.json +1654 -0
- package/test/test_data/inputBlockSpec/kv.json +326 -0
- package/test/test_data/inputBlockSpec/mk1.json +1019 -0
- package/test/test_data/inputBlockSpec/table.json +170 -0
- package/test/test_data/tree/genealogy.json +55 -0
- package/test/test_data/tree/jude.json +15965 -0
- package/test/test_data/tsv/en_tn_66-JUD.tsv +75 -0
- package/test/test_data/tsv/twl_JUD.tsv +144 -0
- package/test/test_data/usfm/1pe_webbe.usfm +13 -0
- package/test/test_data/usfm/66-JUD-ust.usfm +1089 -0
- package/test/test_data/usfm/78-GALspavbl.usfm +10 -0
- package/test/test_data/usfm/add_test.usfm +15 -0
- package/test/test_data/usfm/backslash.usfm +4 -0
- package/test/test_data/usfm/cl.usfm +14 -0
- package/test/test_data/usfm/cp_vp.usfm +8 -0
- package/test/test_data/usfm/custom.usfm +13 -0
- package/test/test_data/usfm/en_ust_oba.usfm +875 -0
- package/test/test_data/usfm/en_ust_psa_1.usfm +20 -0
- package/test/test_data/usfm/fig.usfm +3 -0
- package/test/test_data/usfm/filter.usfm +7 -0
- package/test/test_data/usfm/footnote.usfm +11 -0
- package/test/test_data/usfm/frt.usfm +4 -0
- package/test/test_data/usfm/headings.usfm +7 -0
- package/test/test_data/usfm/hello.usfm +8 -0
- package/test/test_data/usfm/int.usfm +7 -0
- package/test/test_data/usfm/milestone_attributes.usfm +7 -0
- package/test/test_data/usfm/milestone_attributes_default.usfm +7 -0
- package/test/test_data/usfm/no_break_space.usfm +4 -0
- package/test/test_data/usfm/no_mt.usfm +6 -0
- package/test/test_data/usfm/rems.usfm +6 -0
- package/test/test_data/usfm/section_intros.usfm +26 -0
- package/test/test_data/usfm/sidebars.usfm +25 -0
- package/test/test_data/usfm/slash_in_att.usfm +6 -0
- package/test/test_data/usfm/soft_line_break.usfm +4 -0
- package/test/test_data/usfm/spans.usfm +5 -0
- package/test/test_data/usfm/split_long_tokens.usfm +6 -0
- package/test/test_data/usfm/table.usfm +18 -0
- package/test/test_data/usfm/table_at_end.usfm +11 -0
- package/test/test_data/usfm/table_in_intro.usfm +22 -0
- package/test/test_data/usfm/table_no_end_cells.usfm +18 -0
- package/test/test_data/usfm/tit_kitchen_sink.usfm +73 -0
- package/test/test_data/usfm/titus_template.usfm +58 -0
- package/test/test_data/usfm/ugnt_3jn.usfm +265 -0
- package/test/test_data/usfm/ult_3jn.usfm +335 -0
- package/test/test_data/usfm/unknown.usfm +5 -0
- package/test/test_data/usfm/ust_psa.usfm +29 -0
- package/test/test_data/usfm/ust_psa_verse_ranges.usfm +24 -0
- package/test/test_data/usfm/ust_psa_with_ts.usfm +29 -0
- package/test/test_data/usfm/verse_breaks_in_blocks.usfm +20 -0
- package/test/test_data/usfm/verse_range.usfm +7 -0
- package/test/test_data/usfm/web_ecc.usfm +391 -0
- package/test/test_data/usfm/web_psa51.usfm +71 -0
- package/test/test_data/usfm/whitespace.usfm +12 -0
- package/test/test_data/usfm/xref.usfm +11 -0
- package/test/test_data/usx/bad_element.usx +2 -0
- package/test/test_data/usx/cp_vp.usx +12 -0
- package/test/test_data/usx/diff1.usx +59 -0
- package/test/test_data/usx/diff2.usx +74 -0
- package/test/test_data/usx/douay_rheims_ecc.usx +58 -0
- package/test/test_data/usx/douay_rheims_psa.usx +5366 -0
- package/test/test_data/usx/douay_rheims_psa_40_60.usx +666 -0
- package/test/test_data/usx/douay_rheims_rut.usx +26 -0
- package/test/test_data/usx/esg3.usx +47 -0
- package/test/test_data/usx/fig.usx +6 -0
- package/test/test_data/usx/milestone_attributes.usx +11 -0
- package/test/test_data/usx/not_nfc18_glo.usx +9 -0
- package/test/test_data/usx/not_nfc18_phm.usx +24 -0
- package/test/test_data/usx/opt_break.usx +10 -0
- package/test/test_data/usx/sidebars.usx +29 -0
- package/test/test_data/usx/table.usx +23 -0
- package/test/test_data/usx/web_psa.usx +8489 -0
- package/test/test_data/usx/web_psa150.usx +33 -0
- package/test/test_data/usx/web_psa_40_60.usx +1079 -0
- package/test/test_data/usx/web_rut.usx +95 -0
- package/test/test_data/usx/web_rut_1.usx +17 -0
- package/test/test_data/utils/douay_rheims.vrs +520 -0
- package/test/test_data/utils/douay_rheims_PSA.usx +5366 -0
- package/test/test_data/utils/serialize_example.json +91 -0
- package/test/test_data/utils/truncated_versification.vrs +29 -0
- package/test/test_data/utils/web_rut_items.json +2977 -0
- package/test/test_data/utils/webbe.vrs +395 -0
- package/test/test_data/utils/webbe_PSA.usx +8489 -0
- package/test/test_data/vrs/douay_rheims.vrs +520 -0
- package/test/test_data/vrs/truncated_versification.vrs +27 -0
- package/test/test_data/vrs/webbe.vrs +397 -0
- package/webpack.prod.js +50 -0
- package/dist/index.js +0 -8
- package/dist/index.js.LICENSE.txt +0 -23
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const test = require('tape');
|
|
3
|
+
const fse = require('fs-extra');
|
|
4
|
+
const deepEqual = require('deep-equal');
|
|
5
|
+
|
|
6
|
+
const { utils } = require('../../../src/index.cjs');
|
|
7
|
+
const {
|
|
8
|
+
vrs2json,
|
|
9
|
+
reverseVersification,
|
|
10
|
+
preSuccinctVerseMapping,
|
|
11
|
+
succinctifyVerseMappings,
|
|
12
|
+
unsuccinctifyVerseMapping,
|
|
13
|
+
bookCodeIndex,
|
|
14
|
+
mapVerse,
|
|
15
|
+
} = utils.versification;
|
|
16
|
+
|
|
17
|
+
const testGroup = 'Versification';
|
|
18
|
+
|
|
19
|
+
test(
|
|
20
|
+
`vrs2json (${testGroup})`,
|
|
21
|
+
function (t) {
|
|
22
|
+
try {
|
|
23
|
+
t.plan(1);
|
|
24
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
25
|
+
const vrsJson = vrs2json(vrsString);
|
|
26
|
+
// console.log(JSON.stringify(vrsJson));
|
|
27
|
+
t.ok(Object.keys(vrsJson.mappedVerses).length > 0);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.log(err);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
test(
|
|
35
|
+
`reverseVersification (${testGroup})`,
|
|
36
|
+
function (t) {
|
|
37
|
+
try {
|
|
38
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
39
|
+
const vrsJson = vrs2json(vrsString);
|
|
40
|
+
const vrsJsonLength = Object.keys(vrsJson.mappedVerses).length;
|
|
41
|
+
t.plan(vrsJsonLength);
|
|
42
|
+
// console.log(JSON.stringify(vrsJson, null, 2));
|
|
43
|
+
const reversed = reverseVersification(vrsJson);
|
|
44
|
+
|
|
45
|
+
// console.log(JSON.stringify(reversed, null, 2));
|
|
46
|
+
for (const [key, value] of (Object.entries(vrsJson.mappedVerses))) {
|
|
47
|
+
t.ok(value[0] in reversed.reverseMappedVerses);
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.log(err);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
test(
|
|
56
|
+
`preSuccinctVerseMapping (${testGroup})`,
|
|
57
|
+
function (t) {
|
|
58
|
+
try {
|
|
59
|
+
t.plan(18);
|
|
60
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
61
|
+
const vrsJson = vrs2json(vrsString);
|
|
62
|
+
const preSuccinct = preSuccinctVerseMapping(vrsJson.mappedVerses);
|
|
63
|
+
let preSuccinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'S3Y'];
|
|
64
|
+
t.equal(Object.keys(preSuccinct).length, preSuccinctBooks.length);
|
|
65
|
+
|
|
66
|
+
for (const book of preSuccinctBooks) {
|
|
67
|
+
t.ok(book in preSuccinct);
|
|
68
|
+
}
|
|
69
|
+
t.ok('31' in preSuccinct['GEN']);
|
|
70
|
+
t.ok('32' in preSuccinct['GEN']);
|
|
71
|
+
t.ok(preSuccinct['S3Y']['1'][0][2][0].includes('DAG'));
|
|
72
|
+
const reversed = reverseVersification(vrsJson);
|
|
73
|
+
const preSuccinctReversed = preSuccinctVerseMapping(reversed.reverseMappedVerses);
|
|
74
|
+
preSuccinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'DAG'];
|
|
75
|
+
t.equal(Object.keys(preSuccinctReversed).length, preSuccinctBooks.length);
|
|
76
|
+
|
|
77
|
+
for (const book of preSuccinctBooks) {
|
|
78
|
+
t.ok(book in preSuccinctReversed);
|
|
79
|
+
}
|
|
80
|
+
t.ok('5' in preSuccinctReversed['LEV']);
|
|
81
|
+
t.ok('6' in preSuccinctReversed['LEV']);
|
|
82
|
+
t.ok(preSuccinctReversed['DAG']['3'][0][2][0].includes('S3Y'));
|
|
83
|
+
// console.log(JSON.stringify(preSuccinctReversed, null, 2));
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.log(err);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
test(
|
|
91
|
+
`succinctifyVerseMappings (${testGroup})`,
|
|
92
|
+
function (t) {
|
|
93
|
+
try {
|
|
94
|
+
t.plan(16);
|
|
95
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
96
|
+
const vrsJson = vrs2json(vrsString);
|
|
97
|
+
const succinct = succinctifyVerseMappings(vrsJson.mappedVerses);
|
|
98
|
+
let succinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'S3Y'];
|
|
99
|
+
t.equal(Object.keys(succinct).length, succinctBooks.length);
|
|
100
|
+
|
|
101
|
+
for (const book of succinctBooks) {
|
|
102
|
+
t.ok(book in succinct);
|
|
103
|
+
}
|
|
104
|
+
t.ok('31' in succinct['GEN']);
|
|
105
|
+
t.ok('32' in succinct['GEN']);
|
|
106
|
+
const succinctReversed = succinctifyVerseMappings(reverseVersification(vrsJson).reverseMappedVerses);
|
|
107
|
+
succinctBooks = ['GEN', 'LEV', 'PSA', 'ACT', 'DAG'];
|
|
108
|
+
t.equal(Object.keys(succinctReversed).length, succinctBooks.length);
|
|
109
|
+
|
|
110
|
+
for (const book of succinctBooks) {
|
|
111
|
+
t.ok(book in succinctReversed);
|
|
112
|
+
}
|
|
113
|
+
t.ok('5' in succinctReversed['LEV']);
|
|
114
|
+
t.ok('6' in succinctReversed['LEV']);
|
|
115
|
+
// console.log(JSON.stringify(succinct, null, 2));
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.log(err);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
test(
|
|
123
|
+
`unsuccinctify forward (${testGroup})`,
|
|
124
|
+
function (t) {
|
|
125
|
+
try {
|
|
126
|
+
t.plan(15);
|
|
127
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
128
|
+
const vrsJson = vrs2json(vrsString);
|
|
129
|
+
const svm = succinctifyVerseMappings(vrsJson.mappedVerses);
|
|
130
|
+
const unsuccinctS3Y = unsuccinctifyVerseMapping(svm['S3Y']['1'], 'S3Y', bookCodeIndex());
|
|
131
|
+
t.equal(unsuccinctS3Y[0].fromVerseStart, 1);
|
|
132
|
+
t.equal(unsuccinctS3Y[0].fromVerseEnd, 29);
|
|
133
|
+
t.equal(unsuccinctS3Y[0].bookCode, 'DAG');
|
|
134
|
+
t.equal(unsuccinctS3Y[0].mapping[0].ch, 3);
|
|
135
|
+
t.equal(unsuccinctS3Y[0].mapping[0].verseStart, 24);
|
|
136
|
+
const unsuccinctACT = unsuccinctifyVerseMapping(svm['ACT']['19'], 'ACT', bookCodeIndex());
|
|
137
|
+
// console.log(JSON.stringify(unsuccinctACT, null, 2));
|
|
138
|
+
t.equal(unsuccinctACT[0].fromVerseStart, 40);
|
|
139
|
+
t.equal(unsuccinctACT[0].fromVerseEnd, 40);
|
|
140
|
+
t.equal(unsuccinctACT[0].bookCode, 'ACT');
|
|
141
|
+
t.equal(unsuccinctACT[0].mapping[0].ch, 19);
|
|
142
|
+
t.equal(unsuccinctACT[0].mapping[0].verseStart, 40);
|
|
143
|
+
t.equal(unsuccinctACT[1].fromVerseStart, 41);
|
|
144
|
+
t.equal(unsuccinctACT[1].fromVerseEnd, 41);
|
|
145
|
+
t.equal(unsuccinctACT[1].bookCode, 'ACT');
|
|
146
|
+
t.equal(unsuccinctACT[1].mapping[0].ch, 19);
|
|
147
|
+
t.equal(unsuccinctACT[1].mapping[0].verseStart, 40);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
console.log(err);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
test(
|
|
155
|
+
`unsuccinctify reverse (${testGroup})`,
|
|
156
|
+
function (t) {
|
|
157
|
+
try {
|
|
158
|
+
t.plan(12);
|
|
159
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
160
|
+
const vrsJson = vrs2json(vrsString);
|
|
161
|
+
const reversedJson = reverseVersification(vrsJson);
|
|
162
|
+
const svm = succinctifyVerseMappings(reversedJson.reverseMappedVerses);
|
|
163
|
+
const unsuccinctDAG = unsuccinctifyVerseMapping(svm['DAG']['3'], 'DAG', bookCodeIndex());
|
|
164
|
+
t.equal(unsuccinctDAG[0].fromVerseStart, 24);
|
|
165
|
+
t.equal(unsuccinctDAG[0].fromVerseEnd, 52);
|
|
166
|
+
t.equal(unsuccinctDAG[0].bookCode, 'S3Y');
|
|
167
|
+
t.equal(unsuccinctDAG[0].mapping[0].ch, 1);
|
|
168
|
+
t.equal(unsuccinctDAG[0].mapping[0].verseStart, 1);
|
|
169
|
+
const unsuccinctACT = unsuccinctifyVerseMapping(svm['ACT']['19'], 'ACT', bookCodeIndex());
|
|
170
|
+
t.equal(unsuccinctACT[0].fromVerseStart, 40);
|
|
171
|
+
t.equal(unsuccinctACT[0].fromVerseEnd, 40);
|
|
172
|
+
t.equal(unsuccinctACT[0].bookCode, 'ACT');
|
|
173
|
+
t.equal(unsuccinctACT[0].mapping[0].ch, 19);
|
|
174
|
+
t.equal(unsuccinctACT[0].mapping[0].verseStart, 40);
|
|
175
|
+
t.equal(unsuccinctACT[0].mapping[1].ch, 19);
|
|
176
|
+
t.equal(unsuccinctACT[0].mapping[1].verseStart, 41);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.log(err);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
test(
|
|
184
|
+
`mapVerse forward (${testGroup})`,
|
|
185
|
+
function (t) {
|
|
186
|
+
try {
|
|
187
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
188
|
+
const mappings = [
|
|
189
|
+
[['GEN', 31, 1], ['GEN', 31, 1]],
|
|
190
|
+
[['GEN', 31, 55], ['GEN', 32, 1]],
|
|
191
|
+
[['GEN', 32, 17], ['GEN', 32, 18]],
|
|
192
|
+
[['PSA', 51, 0], ['PSA', 51, 1]],
|
|
193
|
+
[['PSA', 51, 1], ['PSA', 51, 3]],
|
|
194
|
+
[['ACT', 19, 40], ['ACT',19, 40]],
|
|
195
|
+
[['ACT', 19, 41], ['ACT',19, 40]],
|
|
196
|
+
[['S3Y', 1, 2], ['DAG', 3, 25]],
|
|
197
|
+
];
|
|
198
|
+
t.plan(3 * mappings.length);
|
|
199
|
+
const vrsJson = vrs2json(vrsString);
|
|
200
|
+
const svm = succinctifyVerseMappings(vrsJson.mappedVerses);
|
|
201
|
+
|
|
202
|
+
for (const [[fromBook, fromCh, fromV], [toBook, toCh, toV]] of mappings) {
|
|
203
|
+
const succinct = svm[fromBook][fromCh.toString()];
|
|
204
|
+
const mapping = mapVerse(succinct, fromBook, fromCh, fromV);
|
|
205
|
+
t.equal(mapping[0], toBook);
|
|
206
|
+
t.equal(mapping[1][0][0], toCh);
|
|
207
|
+
t.equal(mapping[1][0][1], toV);
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
console.log(err);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
test(
|
|
216
|
+
`mapVerse reverse (${testGroup})`,
|
|
217
|
+
function (t) {
|
|
218
|
+
try {
|
|
219
|
+
const vrsString = fse.readFileSync(path.resolve(__dirname, '../../test_data/utils/truncated_versification.vrs')).toString();
|
|
220
|
+
const mappings = [
|
|
221
|
+
[['GEN', 32, 99], ['GEN', [[32, 99]]]],
|
|
222
|
+
[['GEN', 32, 1], ['GEN', [[31, 55]]]],
|
|
223
|
+
[['GEN', 32, 18], ['GEN', [[32, 17]]]],
|
|
224
|
+
[['PSA', 11, 1], ['PSA', [[10, 2]]]],
|
|
225
|
+
[['PSA', 51, 1], ['PSA', [[51, 0]]]],
|
|
226
|
+
[['PSA', 51, 2], ['PSA', [[51, 0]]]],
|
|
227
|
+
[['PSA', 51, 3], ['PSA', [[51, 1]]]],
|
|
228
|
+
[['ACT', 19, 40], ['ACT', [[19, 40], [19, 41]]]],
|
|
229
|
+
[['DAG', 3, 25], ['S3Y', [[1, 2]]]],
|
|
230
|
+
];
|
|
231
|
+
t.plan(2 * mappings.length);
|
|
232
|
+
const forwardJson = vrs2json(vrsString);
|
|
233
|
+
// console.log(JSON.stringify(forwardJson, null, 2))
|
|
234
|
+
const reverseJson = reverseVersification(forwardJson);
|
|
235
|
+
// console.log(JSON.stringify(reverseJson, null, 2))
|
|
236
|
+
const svm = succinctifyVerseMappings(reverseJson.reverseMappedVerses);
|
|
237
|
+
|
|
238
|
+
for (const [[fromBook, fromCh, fromV], [toBook, toSpecs]] of mappings) {
|
|
239
|
+
const succinct = svm[fromBook][fromCh.toString()];
|
|
240
|
+
const mapping = mapVerse(succinct, fromBook, fromCh, fromV);
|
|
241
|
+
t.equal(mapping[0], toBook);
|
|
242
|
+
t.ok(deepEqual(mapping[1], toSpecs));
|
|
243
|
+
}
|
|
244
|
+
} catch (err) {
|
|
245
|
+
console.log(err);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
|
package/test/lib/load.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fse = require('fs-extra');
|
|
3
|
+
|
|
4
|
+
// const pkSrc = (process.env.PKSRC) || 'dist';
|
|
5
|
+
|
|
6
|
+
// const { Proskomma } = require(`../../${pkSrc}/index.cjs`);
|
|
7
|
+
const { Proskomma } = require("../../src/index.cjs");
|
|
8
|
+
|
|
9
|
+
const pkWithDoc = (fp, selectors, options, customTags, emptyBlocks, tags) => {
|
|
10
|
+
if (!options) {
|
|
11
|
+
options = {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const content = fse.readFileSync(path.resolve(__dirname, fp));
|
|
15
|
+
let contentType = fp.split('.').pop();
|
|
16
|
+
|
|
17
|
+
const pk = new Proskomma();
|
|
18
|
+
const pkDoc = pk.importDocument(
|
|
19
|
+
selectors,
|
|
20
|
+
contentType,
|
|
21
|
+
content,
|
|
22
|
+
options,
|
|
23
|
+
customTags,
|
|
24
|
+
emptyBlocks,
|
|
25
|
+
tags,
|
|
26
|
+
);
|
|
27
|
+
return [pk, pkDoc];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const customPkWithDoc = (pkClass, fp, selectors, options) => {
|
|
31
|
+
if (!options) {
|
|
32
|
+
options = {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const content = fse.readFileSync(path.resolve(__dirname, fp));
|
|
36
|
+
let contentType = fp.split('.').pop();
|
|
37
|
+
|
|
38
|
+
const pk = new pkClass();
|
|
39
|
+
const pkDoc = pk.importDocument(
|
|
40
|
+
selectors,
|
|
41
|
+
contentType,
|
|
42
|
+
content,
|
|
43
|
+
options,
|
|
44
|
+
);
|
|
45
|
+
return [pk, pkDoc];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const pkWithDocs = (contentSpecs) => {
|
|
49
|
+
const pk = new Proskomma();
|
|
50
|
+
|
|
51
|
+
for (const [fp, selectors] of contentSpecs) {
|
|
52
|
+
const content = fse.readFileSync(path.resolve(__dirname, fp));
|
|
53
|
+
let contentType = fp.split('.').pop();
|
|
54
|
+
|
|
55
|
+
pk.importDocument(
|
|
56
|
+
selectors,
|
|
57
|
+
contentType,
|
|
58
|
+
content,
|
|
59
|
+
{},
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return pk;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const customPkWithDocs = (pkClass, contentSpecs) => {
|
|
66
|
+
const pk = new pkClass();
|
|
67
|
+
|
|
68
|
+
for (const [fp, selectors] of contentSpecs) {
|
|
69
|
+
const content = fse.readFileSync(path.resolve(__dirname, fp));
|
|
70
|
+
let contentType = fp.split('.').pop();
|
|
71
|
+
|
|
72
|
+
pk.importDocument(
|
|
73
|
+
selectors,
|
|
74
|
+
contentType,
|
|
75
|
+
content,
|
|
76
|
+
{},
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return pk;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const pkWithDocSetDocs = (fps, selectors, options) => {
|
|
83
|
+
if (!options) {
|
|
84
|
+
options = {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const fpContent = [];
|
|
88
|
+
fps.forEach(fp => fpContent.push(fse.readFileSync(path.resolve(__dirname, fp))));
|
|
89
|
+
let contentType = fps[0].split('.').pop();
|
|
90
|
+
|
|
91
|
+
const pk = new Proskomma();
|
|
92
|
+
const pkDocs = pk.importDocuments(
|
|
93
|
+
selectors,
|
|
94
|
+
contentType,
|
|
95
|
+
fpContent,
|
|
96
|
+
options,
|
|
97
|
+
);
|
|
98
|
+
return [pk, pkDocs];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const escapeStringQuotes = str => str.replace(/"/g, '\\"').replace(/'/, '\\\'');
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
pkWithDoc,
|
|
105
|
+
customPkWithDoc,
|
|
106
|
+
pkWithDocs,
|
|
107
|
+
customPkWithDocs,
|
|
108
|
+
pkWithDocSetDocs,
|
|
109
|
+
escapeStringQuotes,
|
|
110
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
const test = require('tape');
|
|
3
|
+
|
|
4
|
+
const { pkWithDocs } = require('../lib/load.js');
|
|
5
|
+
|
|
6
|
+
const testGroup = 'Diff';
|
|
7
|
+
|
|
8
|
+
const pk = pkWithDocs([
|
|
9
|
+
['../test_data/usx/diff1.usx', {
|
|
10
|
+
lang: 'eng',
|
|
11
|
+
abbr: 'web',
|
|
12
|
+
}],
|
|
13
|
+
['../test_data/usx/diff2.usx', {
|
|
14
|
+
lang: 'eng',
|
|
15
|
+
abbr: 'web2',
|
|
16
|
+
}],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
const docIds = Object.keys(pk.documents);
|
|
20
|
+
|
|
21
|
+
test(
|
|
22
|
+
`Compare 2 documents (${testGroup})`,
|
|
23
|
+
async function (t) {
|
|
24
|
+
try {
|
|
25
|
+
const expected = [
|
|
26
|
+
['words', 1, 1, 5, 3, 2],
|
|
27
|
+
['tokens', 1, 1, 5, 3, 4],
|
|
28
|
+
];
|
|
29
|
+
t.plan(6 * expected.length);
|
|
30
|
+
|
|
31
|
+
for (const expectation of expected) {
|
|
32
|
+
const query = `
|
|
33
|
+
{
|
|
34
|
+
diff(
|
|
35
|
+
document1: "${docIds[0]}" document2: "${docIds[1]}" mode: "%mode%"
|
|
36
|
+
) {
|
|
37
|
+
chapter verse diffType text1 text2 tokensDiff wordsDiff
|
|
38
|
+
}
|
|
39
|
+
}`.replace('%mode%', expectation[0]);
|
|
40
|
+
const result = await pk.gqlQuery(query);
|
|
41
|
+
t.equal(result.errors, undefined);
|
|
42
|
+
const diff = result.data.diff;
|
|
43
|
+
t.equal(diff.filter(d => d.diffType === 'addedChapter').length, expectation[1]);
|
|
44
|
+
t.equal(diff.filter(d => d.diffType === 'removedChapter').length, expectation[2]);
|
|
45
|
+
t.equal(diff.filter(d => d.diffType === 'addedVerse').length, expectation[3]);
|
|
46
|
+
t.equal(diff.filter(d => d.diffType === 'removedVerse').length, expectation[4]);
|
|
47
|
+
t.equal(diff.filter(d => d.diffType === 'changedVerse').length, expectation[5]);
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.log(err);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
);
|