UNPKG

pipeline-handler

Version:

an idependant handler for pipelines (like in perfidy or epitelete)

1,172 lines (1,133 loc) 74.5 kB
var $6uPpa$proskommajsontools = require("proskomma-json-tools"); var $6uPpa$xregexp = require("xregexp"); var $6uPpa$deepcopyall = require("deep-copy-all"); function $parcel$interopDefault(a) { return a && a.__esModule ? a.default : a; } var $49d159292df308f8$exports = {}; $49d159292df308f8$exports = JSON.parse('[{"id":0,"type":"Inputs","inputs":{"usfm":"text","selectors":"json"}},{"id":2,"title":"USFM to PERF","name":"usfm2perf","type":"Transform","inputs":[{"name":"usfm","type":"text","source":"Input usfm"},{"name":"selectors","type":"json","source":"Input selectors"}],"outputs":[{"name":"perf","type":"json"}],"description":"USFM=>PERF: Conversion via Proskomma"},{"id":999,"type":"Outputs","outputs":[{"name":"perf","type":"json","source":"Transform 2 perf"}]}]'); var $e03d6d4624dc5adb$exports = {}; $e03d6d4624dc5adb$exports = JSON.parse('[{"id":0,"type":"Inputs","inputs":{"perf":"json","strippedAlignment":"json"}},{"id":1,"title":"Count stripped perf words","name":"verseWords","transformName":"verseWords","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Input perf"}],"outputs":[{"name":"verseWords","type":"json"}],"description":"PERF=>JSON: Counts words occurrences"},{"id":2,"title":"Merge Back Into Stripped (roundtrip)","name":"mergeAlignment","transformName":"mergeAlignment","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Input perf"},{"name":"strippedAlignment","type":"json","source":"Input strippedAlignment"},{"name":"verseWords","type":"json","source":"Transform 1 verseWords"}],"outputs":[{"name":"perf","type":"json"}],"description":"PERF=>PERF adds report to verses"},{"id":3,"title":"Merge Merged PERF Text","name":"mergePerfText","transformName":"mergePerfText","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Transform 2 perf"}],"outputs":[{"name":"perf","type":"json"}],"description":"PERF=>PERF: Merge consecutive text strings"},{"id":999,"type":"Outputs","outputs":[{"name":"perf","type":"json","source":"Transform 3 perf"}]}]'); var $f11b2aab4f58bb2e$exports = {}; $f11b2aab4f58bb2e$exports = JSON.parse('[{"id":0,"type":"Inputs","inputs":{"perf":"json"}},{"id":4,"title":"Transform 4","name":"verseWords","type":"Transform","transformName":"verseWords","inputs":[{"name":"perf","type":"json","source":"Input perf"}],"outputs":[{"name":"verseWords","type":"json"}],"description":"PERF=>JSON: Counts words occurrences"},{"id":6,"title":"Strip Alignment","name":"stripAlignment","type":"Transform","transformName":"stripAlignment","inputs":[{"name":"perf","type":"json","source":"Input perf"},{"name":"verseWords","type":"json","source":"Transform 4 verseWords"}],"outputs":[{"name":"perf","type":"json"},{"name":"strippedAlignment","type":"json"}],"description":"PERF=>PERF: Strips alignment markup"},{"id":9,"title":"Merge stripped perf","name":"mergePerfText","type":"Transform","transformName":"mergePerfText","inputs":[{"name":"perf","type":"json","source":"Transform 6 perf"}],"outputs":[{"name":"perf","type":"json"}],"description":"PERF=>PERF: Merge consecutive text strings"},{"id":999,"type":"Outputs","outputs":[{"name":"perf","type":"json","source":"Transform 9 perf"},{"name":"strippedAlignment","type":"json","source":"Transform 6 strippedAlignment"}]}]'); var $823d53fe4d7d2a85$exports = {}; $823d53fe4d7d2a85$exports = JSON.parse('[{"id":0,"type":"Inputs","inputs":{"perf":"json"}},{"id":1,"title":"Generate report","name":"calculateUsfmChapterPositions","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Input perf"}],"outputs":[{"name":"report","type":"json"}],"description":"Generate report from perf to calculate the position of the chapters"},{"id":2,"title":"PERF to USFM","name":"perf2usfm","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Input perf"},{"name":"report","type":"json","source":"Transform 1 report"}],"outputs":[{"name":"usfm","type":"text"}],"description":"PERF=>USFM: Conversion via Proskomma"},{"id":999,"type":"Outputs","outputs":[{"name":"usfm","type":"text","source":"Transform 2 usfm"}]}]'); var $b5fab095753622af$exports = {}; $b5fab095753622af$exports = JSON.parse('[{"id":0,"type":"Inputs","inputs":{"perf":"json"}},{"id":1,"title":"Simplify Input PERF","name":"justTheBible","transformName":"justTheBible","type":"Transform","inputs":[{"name":"perf","type":"json","source":"Input perf"}],"outputs":[{"name":"perf","type":"json"}]},{"id":999,"type":"Outputs","outputs":[{"name":"perf","type":"json","source":"Transform 1 perf"}]}]'); var $4471298e23cccd36$export$2e2bcd8739ae039 = { usfm2perfPipeline: (/*@__PURE__*/$parcel$interopDefault($49d159292df308f8$exports)), mergeAlignmentPipeline: (/*@__PURE__*/$parcel$interopDefault($e03d6d4624dc5adb$exports)), stripAlignmentPipeline: (/*@__PURE__*/$parcel$interopDefault($f11b2aab4f58bb2e$exports)), perf2usfmPipeline: (/*@__PURE__*/$parcel$interopDefault($823d53fe4d7d2a85$exports)), justTheBiblePipeline: (/*@__PURE__*/$parcel$interopDefault($b5fab095753622af$exports)) }; var $d85258d9da4d121e$exports = {}; const $d85258d9da4d121e$var$usfm2perfCode = function({ usfm: usfm , selectors: selectors , proskomma: proskomma }) { proskomma.importDocuments(selectors, "usfm", [ usfm ]); const perfResultDocument = proskomma.gqlQuerySync("{documents {id docSetId perf} }").data.documents[0]; const docId = perfResultDocument.id; const docSetId = perfResultDocument.docSetId; proskomma.gqlQuerySync(`mutation { deleteDocument(docSetId: "${docSetId}", documentId: "${docId}") }`); const perf = JSON.parse(perfResultDocument.perf); return { perf: perf }; }; const $d85258d9da4d121e$var$usfm2perf = { name: "usfm2perf", type: "Transform", description: "USFM=>PERF: Conversion via Proskomma", inputs: [ { name: "usfm", type: "text", source: "" }, { name: "selectors", type: "json", source: "" } ], outputs: [ { name: "perf", type: "json" } ], code: $d85258d9da4d121e$var$usfm2perfCode }; $d85258d9da4d121e$exports = $d85258d9da4d121e$var$usfm2perf; var $cf2af0c75992d840$exports = {}; const $cf2af0c75992d840$var$identityActions = { startDocument: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ output.perf = {}; output.perf.schema = context.document.schema; output.perf.metadata = context.document.metadata; output.perf.sequences = {}; } } ], endDocument: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{} } ], startSequence: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ output.perf.sequences[context.sequences[0].id] = { type: context.sequences[0].type, blocks: [] }; workspace.outputSequence = output.perf.sequences[context.sequences[0].id]; if (context.sequences[0].type === "main") output.perf.main_sequence_id = context.sequences[0].id; } } ], endSequence: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ if (context.sequences.length > 1) workspace.outputSequence = output.perf.sequences[context.sequences[1].id]; } } ], blockGraft: [ { description: "identity", test: ()=>true, action: (environment)=>{ const currentBlock = environment.context.sequences[0].block; const graftRecord = { type: currentBlock.type, subtype: currentBlock.subType }; if (currentBlock.target) { graftRecord.target = currentBlock.target; environment.context.renderer.renderSequenceId(environment, graftRecord.target); } if (currentBlock.isNew) graftRecord.new = currentBlock.isNew; environment.workspace.outputSequence.blocks.push(graftRecord); } } ], startParagraph: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const currentBlock = context.sequences[0].block; const paraRecord = { type: currentBlock.type, subtype: currentBlock.subType, content: [] }; workspace.outputSequence.blocks.push(paraRecord); workspace.currentContent = paraRecord.content; workspace.outputBlock = workspace.outputSequence.blocks[workspace.outputSequence.blocks.length - 1]; workspace.outputContentStack = [ workspace.outputBlock.content ]; } } ], endParagraph: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{} } ], metaContent: [ { description: "identity", test: ()=>true, action: (environment)=>{ const { config: config , context: context , workspace: workspace , output: output } = environment; const element = context.sequences[0].element; workspace.currentContent = element.metaContent; const lastOutputItem = workspace.outputContentStack[1][workspace.outputContentStack[1].length - 1]; lastOutputItem.meta_content = []; workspace.outputContentStack.unshift(lastOutputItem.meta_content); context.renderer.renderContent(workspace.currentContent, environment); workspace.outputContentStack.shift(); } } ], mark: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; const markRecord = { type: element.type, subtype: element.subType }; if (element.atts && typeof element.atts === "object" && Object.keys(element.atts).length !== 0) markRecord.atts = element.atts; workspace.outputContentStack[0].push(markRecord); } } ], inlineGraft: [ { description: "identity", test: ()=>true, action: (environment)=>{ const element = environment.context.sequences[0].element; const graftRecord = { type: element.type, subtype: element.subType }; if (element.target) { graftRecord.target = element.target; const currentContent = environment.workspace.outputContentStack[0]; environment.context.renderer.renderSequenceId(environment, element.target); environment.workspace.outputContentStack[0] = currentContent; // Probably need more for nesting! } if (element.isNew) graftRecord.new = element.isNew; environment.workspace.outputContentStack[0].push(graftRecord); } } ], startWrapper: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; const wrapperRecord = { type: element.type, subtype: element.subType, content: [] }; if ("atts" in element && typeof element.atts === "object" && Object.keys(element.atts).length !== 0) wrapperRecord.atts = element.atts; workspace.outputContentStack[0].push(wrapperRecord); workspace.outputContentStack.unshift(wrapperRecord.content); } } ], endWrapper: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ workspace.outputContentStack.shift(); } } ], startMilestone: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; const milestoneRecord = { type: element.type, subtype: element.subType }; if (element.atts && typeof element.atts === "object" && Object.keys(element.atts).length !== 0) milestoneRecord.atts = element.atts; workspace.outputContentStack[0].push(milestoneRecord); } } ], endMilestone: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; const milestoneRecord = { type: element.type, subtype: element.subType }; workspace.outputContentStack[0].push(milestoneRecord); } } ], text: [ { description: "identity", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; workspace.outputContentStack[0].push(element.text); } } ] }; $cf2af0c75992d840$exports = $cf2af0c75992d840$var$identityActions; const $da750456a5b71b33$var$initialBlockRecord = (ct)=>({ type: ct.sequences[0].block.type, subType: ct.sequences[0].block.subType, pos: ct.sequences[0].block.blockN, perfChapter: null }); const $da750456a5b71b33$var$calculateUsfmChapterPositionsActions = { startDocument: [ { description: "Set up storage", test: ()=>true, action: ({ workspace: workspace , output: output })=>{ workspace.blockRecords = []; output.report = {}; } } ], startParagraph: [ { description: "Set up block record", test: ()=>true, action: ({ context: context , workspace: workspace , output: output })=>{ workspace.blockRecords.push($da750456a5b71b33$var$initialBlockRecord(context)); } } ], blockGraft: [ { description: "Set up block record", test: ()=>true, action: ({ context: context , workspace: workspace , output: output })=>{ workspace.blockRecords.push($da750456a5b71b33$var$initialBlockRecord(context)); } } ], mark: [ { description: "Add chapter number to block record", test: ({ context: context })=>context.sequences[0].element.subType === "chapter", action: ({ config: config , context: context , workspace: workspace , output: output })=>{ workspace.blockRecords[workspace.blockRecords.length - 1].perfChapter = context.sequences[0].element.atts["number"]; } } ], endDocument: [ { description: "Populate report", test: ()=>true, action: ({ workspace: workspace , output: output })=>{ for (const [recordN, record] of Object.entries(workspace.blockRecords)){ if (!record.perfChapter) continue; let usfmChapterPos = recordN; let found = false; while(usfmChapterPos > 0 && !found)if (workspace.blockRecords[usfmChapterPos - 1].type === "paragraph" || workspace.blockRecords[usfmChapterPos - 1].subType === "title") found = true; else usfmChapterPos--; output.report[usfmChapterPos.toString()] = record.perfChapter; } } } ] }; const $da750456a5b71b33$var$calculateUsfmChapterPositionsCode = function({ perf: perf }) { const cl = new (0, $6uPpa$proskommajsontools.PerfRenderFromJson)({ srcJson: perf, actions: $da750456a5b71b33$var$calculateUsfmChapterPositionsActions }); const output = {}; cl.renderDocument({ docId: "", config: { maxLength: 60 }, output: output }); return { report: output.report }; }; const $da750456a5b71b33$var$calculateUsfmChapterPositions = { name: "calculateUsfmChapterPositions", type: "Transform", description: "PERF=>JSON: Generates positions for inserting chapter numbers into USFM", inputs: [ { name: "perf", type: "json", source: "" } ], outputs: [ { name: "report", type: "json" } ], code: $da750456a5b71b33$var$calculateUsfmChapterPositionsCode }; var $da750456a5b71b33$export$2e2bcd8739ae039 = $da750456a5b71b33$var$calculateUsfmChapterPositions; const $4666fa15adab3ecf$var$oneifyTag = (t)=>{ if ([ "toc", "toca", "mt", "imt", "s", "ms", "mte", "sd" ].includes(t)) return t + "1"; return t; }; const $4666fa15adab3ecf$var$buildMilestone = (type, atts = {})=>{ if (atts == null) atts = {}; let str = `\\${type}-s |`; for (let [key, value] of Object.entries(atts))if (key === "x-morph" && typeof value !== "string") str = str + $4666fa15adab3ecf$var$oneifyTag(key) + '="' + value.join(",") + '" '; else str = str + $4666fa15adab3ecf$var$oneifyTag(key) + '="' + value + '" '; return str + "\\*"; }; const $4666fa15adab3ecf$var$buildEndWrapper = (type, atts = {}, isnested = false)=>{ if (atts == null) atts = {}; let str = "|"; for (let [key, value] of Object.entries(atts))str = str + $4666fa15adab3ecf$var$oneifyTag(key) + '="' + value + '" '; str = str + "\\"; // if it's nested, we simply add a "+" sign before the type if (isnested) str = str + "+"; return str + type + "*"; }; const $4666fa15adab3ecf$var$localToUsfmActions = { startDocument: [ { description: "Set up environment", test: ()=>true, action: ({ context: context , workspace: workspace })=>{ workspace.usfmBits = [ "" ]; workspace.nestedWrapper = 0; for (let [key, value] of Object.entries(context.document.metadata.document).filter((kv)=>![ "tags", "properties", "bookCode", "cl" ].includes(kv[0])))workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(key)} ${value}\n`); } } ], blockGraft: [ { description: "Follow block grafts", test: ({ context: context })=>[ "title", "heading", "introduction" ].includes(context.sequences[0].block.subType), action: (environment)=>{ let contextSequence = environment.context.sequences[0]; let chapterValue = environment.config.report[contextSequence.block.blockN.toString()]; const target = contextSequence.block.target; if (chapterValue && contextSequence.type === "main") environment.workspace.usfmBits.push(`\n\\c ${chapterValue}\n`); if (target) environment.context.renderer.renderSequenceId(environment, target); } } ], inlineGraft: [ { description: "Follow inline grafts", test: ()=>true, action: (environment)=>{ const target = environment.context.sequences[0].element.target; if (target) environment.context.renderer.renderSequenceId(environment, target); } } ], startParagraph: [ { description: "Output footnote paragraph tag (footnote)", test: ({ context: context })=>context.sequences[0].block.subType === "usfm:f" && context.sequences[0].type === "footnote" || context.sequences[0].block.subType === "usfm:x" && context.sequences[0].type === "xref", action: ({ context: context , workspace: workspace , config: config })=>{ workspace.nestedWrapper = 0; let contextSequence = context.sequences[0]; workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(contextSequence.block.subType.split(":")[1])} `); } }, { description: "Output footnote note_caller tag (footnote)", test: ({ context: context })=>context.sequences[0].block.subType === "usfm:f" || context.sequences[0].block.subType === "usfm:x", action: ({ context: context , workspace: workspace , config: config })=>{ workspace.nestedWrapper = 0; } }, { description: "Output paragraph tag (main)", test: ()=>true, action: ({ context: context , workspace: workspace , config: config })=>{ workspace.nestedWrapper = 0; let contextSequence = context.sequences[0]; let chapterValue = config.report[contextSequence.block.blockN.toString()]; if (chapterValue && contextSequence.type === "main") workspace.usfmBits.push(`\n\\c ${chapterValue}\n`); workspace.usfmBits.push(`\n\\${$4666fa15adab3ecf$var$oneifyTag(contextSequence.block.subType.split(":")[1])}\n`); } } ], endParagraph: [ { description: "Output footnote paragraph tag (footnote)", test: ({ context: context })=>context.sequences[0].block.subType === "usfm:f" && context.sequences[0].type === "footnote" || context.sequences[0].block.subType === "usfm:x" && context.sequences[0].type === "xref", action: ({ context: context , workspace: workspace , config: config })=>{ let contextSequence = context.sequences[0]; workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(contextSequence.block.subType.split(":")[1])}*`); } }, { description: "Output footnote note_caller tag (footnote)", test: ({ context: context })=>context.sequences[0].block.subType === "usfm:f" || context.sequences[0].block.subType === "usfm:x", action: ({ context: context , workspace: workspace , config: config })=>{} }, { description: "Output nl", test: ()=>true, action: ({ workspace: workspace })=>{ workspace.usfmBits.push(`\n`); } } ], startMilestone: [ { description: "Output start milestone", test: ()=>true, action: ({ context: context , workspace: workspace })=>{ let contextSequenceElement = context.sequences[0].element; let newStartMileStone = $4666fa15adab3ecf$var$buildMilestone($4666fa15adab3ecf$var$oneifyTag(contextSequenceElement.subType.split(":")[1]), contextSequenceElement.atts); workspace.usfmBits.push(newStartMileStone); } } ], endMilestone: [ { description: "Output end milestone", test: ()=>true, action: ({ context: context , workspace: workspace })=>{ workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(context.sequences[0].element.subType.split(":")[1])}-e\\*`); } } ], text: [ { description: "Output text", test: ()=>true, action: ({ context: context , workspace: workspace })=>{ const text = context.sequences[0].element.text; workspace.usfmBits.push(text); } } ], mark: [ { description: "Output chapter or verses", test: ()=>true, action: ({ context: context , workspace: workspace })=>{ const element = context.sequences[0].element; if (element.subType === "verses") workspace.usfmBits.push(`\n\\v ${element.atts["number"]}\n`); } } ], endSequence: [ { description: "Output \\cl", test: ({ context: context })=>context.document.metadata.document.cl && context.sequences[0].type === "title", action: ({ context: context , workspace: workspace })=>{ workspace.usfmBits.push(`\n\\cl ${context.document.metadata.document.cl}\n`); } } ], startWrapper: [ { description: "Output start tag", test: ()=>true, action: ({ workspace: workspace , context: context })=>{ let contextSequence = context.sequences[0]; // handle nested wrappers : https://ubsicap.github.io/usfm/characters/nesting.html if (workspace.nestedWrapper > 0) workspace.usfmBits.push(`\\+${$4666fa15adab3ecf$var$oneifyTag(contextSequence.element.subType.split(":")[1])} `); else workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(contextSequence.element.subType.split(":")[1])} `); workspace.nestedWrapper += 1; } } ], endWrapper: [ { description: "Output end tag", test: ({ context: context })=>![ "fr", "fq", "fqa", "fk", "fl", "fw", "fp", "ft", "xo", "xk", "xq", "xt", "xta" ].includes(context.sequences[0].element.subType.split(":")[1]), action: ({ workspace: workspace , context: context })=>{ workspace.nestedWrapper -= 1; let contextSequence = context.sequences[0]; let subType = contextSequence.element.subType.split(":")[1]; let isNested = workspace.nestedWrapper > 0; if (subType === "w") { let newEndW = $4666fa15adab3ecf$var$buildEndWrapper($4666fa15adab3ecf$var$oneifyTag(subType), contextSequence.element.atts, isNested); workspace.usfmBits.push(newEndW); } else // handle nested wrappers : https://ubsicap.github.io/usfm/characters/nesting.html if (isNested) workspace.usfmBits.push(`\\+${$4666fa15adab3ecf$var$oneifyTag(contextSequence.element.subType.split(":")[1])}*`); else workspace.usfmBits.push(`\\${$4666fa15adab3ecf$var$oneifyTag(contextSequence.element.subType.split(":")[1])}*`); } }, { description: "Do NOT output end tag", test: ()=>true, action: ({ workspace: workspace })=>{ workspace.nestedWrapper -= 1; } } ], endDocument: [ { description: "Build output", test: ()=>true, action: ({ workspace: workspace , output: output })=>{ output.usfm = workspace.usfmBits.join("").replace(/(\s*)\n(\s*)/gm, "\n"); } } ] }; const $4666fa15adab3ecf$var$perf2usfmCode = function({ perf: perf , report: report }) { const cl = new (0, $6uPpa$proskommajsontools.PerfRenderFromJson)({ srcJson: perf, actions: $4666fa15adab3ecf$var$localToUsfmActions }); const output = {}; cl.renderDocument({ docId: "", config: { report: report }, output: output }); return { usfm: output.usfm }; }; const $4666fa15adab3ecf$var$perf2usfm = { name: "perf2usfm", type: "Transform", description: "PERF=>USFM", inputs: [ { name: "perf", type: "json", source: "" }, { name: "report", type: "json", source: "" } ], outputs: [ { name: "usfm", type: "text" } ], code: $4666fa15adab3ecf$var$perf2usfmCode }; var $4666fa15adab3ecf$export$2e2bcd8739ae039 = $4666fa15adab3ecf$var$perf2usfm; const $634669135dc5cc02$var$localVerseWordsActions = { startDocument: [ { description: "Set up storage", test: ()=>true, action: ({ workspace: workspace , output: output })=>{ workspace.verseContent = []; workspace.chapter = null; workspace.verses = null; output.cv = {}; } } ], mark: [ { description: "Update CV state", test: ()=>true, action: ({ context: context , workspace: workspace , output: output })=>{ const { element: element } = context.sequences[0]; if (element.subType === "chapter") { workspace.chapter = element.atts["number"]; workspace.verses = 0; output.cv[workspace.chapter] = {}; output.cv[workspace.chapter][workspace.verses] = {}; } else if (element.subType === "verses") { workspace.verses = element.atts["number"]; output.cv[workspace.chapter][workspace.verses] = {}; } } } ], text: [ { description: "Log occurrences", test: ()=>true, action: ({ context: context , workspace: workspace , output: output })=>{ const { chapter: chapter , verses: verses } = workspace; const { text: text } = context.sequences[0].element; const re = (0, ($parcel$interopDefault($6uPpa$xregexp)))("([\\p{Letter}\\p{Number}\\p{Mark}\\u2060]{1,127})"); const words = (0, ($parcel$interopDefault($6uPpa$xregexp))).match(text, re, "all"); for (const word of words){ output.cv[chapter][verses][word] ??= 0; output.cv[chapter][verses][word] += 1; } } } ] }; const $634669135dc5cc02$var$verseWordsCode = function({ perf: perf }) { const cl = new (0, $6uPpa$proskommajsontools.PerfRenderFromJson)({ srcJson: perf, actions: $634669135dc5cc02$var$localVerseWordsActions }); const output = {}; cl.renderDocument({ docId: "", config: {}, output: output }); return { verseWords: output.cv }; }; const $634669135dc5cc02$var$verseWords = { name: "verseWords", type: "Transform", description: "PERF=>JSON: Counts words occurrences", inputs: [ { name: "perf", type: "json", source: "" } ], outputs: [ { name: "verseWords", type: "json" } ], code: $634669135dc5cc02$var$verseWordsCode }; var $634669135dc5cc02$export$2e2bcd8739ae039 = $634669135dc5cc02$var$verseWords; const $a80b95f24ce74645$var$localStripMarkupActions = { startDocument: [ { description: "Set up", test: ()=>true, action: ({ workspace: workspace , output: output , context: context })=>{ workspace.chapter = null; workspace.verses = null; workspace.lastWord = ""; workspace.waitingMarkup = []; workspace.currentOccurrences = {}; workspace.PendingStartMilestones = []; output.stripped = {}; return true; } } ], startMilestone: [ { description: "Ignore zaln startMilestone events", test: ({ context: context })=>context.sequences[0].element.subType === "usfm:zaln", action: ({ context: context , workspace: workspace })=>{ const payload = context.sequences[0].element; payload.subtype = payload.subType; delete payload.subType; workspace.waitingMarkup.push(payload); workspace.PendingStartMilestones.push(payload); } } ], endMilestone: [ { description: "Ignore zaln endMilestone events", test: ({ context: context })=>context.sequences[0].element.subType === "usfm:zaln", action: ({ context: context , workspace: workspace , output: output , config: config })=>{ const { chapter: chapter , verses: verses , lastWord: word } = workspace; const { verseWords: totalOccurrences } = config; const strippedKey = [ "after", word, workspace.currentOccurrences[word], totalOccurrences[chapter][verses][word] ].join("--"); const payload = { ...context.sequences[0].element }; payload.subtype = payload.subType; delete payload.subType; const record = { chapter: chapter, verses: verses, occurrence: workspace.currentOccurrences[word], occurrences: totalOccurrences[chapter][verses][word], position: "after", word: word, payload: payload, startMilestone: workspace.PendingStartMilestones.shift() }; if (!output.stripped[workspace.chapter][workspace.verses][strippedKey]) output.stripped[workspace.chapter][workspace.verses][strippedKey] = [ record ]; else output.stripped[workspace.chapter][workspace.verses][strippedKey].push(record); return false; } } ], startWrapper: [ { description: "Ignore w startWrapper events", test: ({ context: context })=>context.sequences[0].element.subType === "usfm:w", action: ({ context: context , workspace: workspace })=>{ const payload = { ...context.sequences[0].element }; payload.subtype = payload.subType; delete payload.subType; workspace.waitingMarkup.push(payload); } } ], endWrapper: [ { description: "Ignore w endWrapper events", test: ({ context: context })=>context.sequences[0].element.subType === "usfm:w", action: ({ context: context })=>{} } ], text: [ { description: "Log occurrences", test: ()=>true, action: ({ context: context , workspace: workspace , output: output , config: config })=>{ try { const text = context.sequences[0].element.text; const re = (0, ($parcel$interopDefault($6uPpa$xregexp)))("([\\p{Letter}\\p{Number}\\p{Mark}\\u2060]{1,127})"); const words = (0, ($parcel$interopDefault($6uPpa$xregexp))).match(text, re, "all"); const { chapter: chapter , verses: verses } = workspace; const { verseWords: totalOccurrences } = config; for (const word of words){ workspace.currentOccurrences[word] ??= 0; workspace.currentOccurrences[word]++; while(workspace.waitingMarkup.length){ const payload = workspace.waitingMarkup.shift(); const strippedKey = [ "before", word, workspace.currentOccurrences[word], totalOccurrences[chapter][verses][word] ].join("--"); const record = { chapter: chapter, verses: verses, occurrence: workspace.currentOccurrences[word], occurrences: totalOccurrences[chapter][verses][word], position: "before", word: word, payload: { ...payload, ...payload.subtype === "usfm:w" && { content: [ word ] } } }; if (!output.stripped[workspace.chapter][workspace.verses][strippedKey]) output.stripped[workspace.chapter][workspace.verses][strippedKey] = [ record ]; else output.stripped[workspace.chapter][workspace.verses][strippedKey].push(record); } workspace.lastWord = word; } } catch (err) { throw new Error(err); } return true; } } ], mark: [ { description: "Update CV state", test: ()=>true, action: ({ context: context , workspace: workspace , output: output })=>{ try { const element = context.sequences[0].element; if (element.subType === "chapter") { workspace.chapter = element.atts["number"]; workspace.verses = 0; workspace.lastWord = ""; workspace.currentOccurrences = {}; output.stripped[workspace.chapter] = {}; output.stripped[workspace.chapter][workspace.verses] = {}; } else if (element.subType === "verses") { workspace.verses = element.atts["number"]; workspace.lastWord = ""; workspace.currentOccurrences = {}; output.stripped[workspace.chapter][workspace.verses] = {}; } } catch (err) { throw new Error(err); } return true; } } ] }; const $a80b95f24ce74645$var$stripMarkupCode = function({ perf: perf , verseWords: verseWords }) { const cl = new (0, $6uPpa$proskommajsontools.PerfRenderFromJson)({ srcJson: perf, actions: (0, $6uPpa$proskommajsontools.mergeActions)([ $a80b95f24ce74645$var$localStripMarkupActions, (0, $1dce2ba16e048662$export$2e2bcd8739ae039).identityActions ]) }); const output = {}; cl.renderDocument({ docId: "", config: { verseWords: verseWords }, output: output }); return { perf: output.perf, strippedAlignment: output.stripped }; }; const $a80b95f24ce74645$var$stripAlignment = { name: "stripAlignment", type: "Transform", description: "PERF=>PERF: Strips alignment markup", inputs: [ { name: "perf", type: "json", source: "" }, { name: "verseWords", type: "json", source: "" } ], outputs: [ { name: "perf", type: "json" }, { name: "strippedAlignment", type: "json" } ], code: $a80b95f24ce74645$var$stripMarkupCode }; var $a80b95f24ce74645$export$2e2bcd8739ae039 = $a80b95f24ce74645$var$stripAlignment; const $2525ca6bc59b4b8b$var$doMerge1 = (content)=>{ let ret = []; for (const element of content)if (typeof element === "string") { if (ret.length > 0 && typeof ret[ret.length - 1] === "string") ret[ret.length - 1] += element; else ret.push(element); } else { if (element.content) element.content = $2525ca6bc59b4b8b$var$doMerge1(element.content); if (element.metaContent) element.metaContent = $2525ca6bc59b4b8b$var$doMerge1(element.content); ret.push(element); } return ret; }; const $2525ca6bc59b4b8b$var$doMerge = (perf)=>{ const newPerf = (0, ($parcel$interopDefault($6uPpa$deepcopyall)))(perf); for (const seq of Object.values(newPerf.sequences))for (const block of seq.blocks){ if (block.content) block.content = $2525ca6bc59b4b8b$var$doMerge1(block.content); if (block.metaContent) block.metaContent = $2525ca6bc59b4b8b$var$doMerge1(block.metaContent); } return newPerf; }; const $2525ca6bc59b4b8b$var$mergePerfTextCode = function({ perf: perf }) { return { perf: $2525ca6bc59b4b8b$var$doMerge(perf) }; }; const $2525ca6bc59b4b8b$var$mergePerfText = { name: "mergePerfText", type: "Transform", description: "PERF=>PERF: Merge consecutive text strings", inputs: [ { name: "perf", type: "json", source: "" } ], outputs: [ { name: "perf", type: "json" } ], code: $2525ca6bc59b4b8b$var$mergePerfTextCode }; var $2525ca6bc59b4b8b$export$2e2bcd8739ae039 = $2525ca6bc59b4b8b$var$mergePerfText; const $78d0e219f1596209$var$lexingRegexes = [ [ "printable", "wordLike", (0, ($parcel$interopDefault($6uPpa$xregexp)))("([\\p{Letter}\\p{Number}\\p{Mark}\\u2060]{1,127})") ], [ "printable", "lineSpace", (0, ($parcel$interopDefault($6uPpa$xregexp)))("([\\p{Separator} ]{1,127})") ], [ "printable", "punctuation", (0, ($parcel$interopDefault($6uPpa$xregexp)))("([\\p{Punctuation}\\p{Math_Symbol}\\p{Currency_Symbol}\\p{Modifier_Symbol}\\p{Other_Symbol}])") ], [ "bad", "unknown", (0, ($parcel$interopDefault($6uPpa$xregexp)))("(.)") ] ]; const $78d0e219f1596209$var$re = (0, ($parcel$interopDefault($6uPpa$xregexp))).union($78d0e219f1596209$var$lexingRegexes.map((x)=>x[2])); const $78d0e219f1596209$var$endMilestone = { type: "end_milestone", subtype: "usfm:zaln" }; const $78d0e219f1596209$var$localMergeAlignmentActions = { startDocument: [ { description: "setup", test: ()=>true, action: ({ workspace: workspace })=>{ workspace.chapter = null; workspace.verses = null; workspace.currentOccurrences = {}; return true; } } ], text: [ { description: "add-to-text", test: ()=>true, action: ({ config: config , context: context , workspace: workspace , output: output })=>{ try { const text = context.sequences[0].element.text; const words = (0, ($parcel$interopDefault($6uPpa$xregexp))).match(text, $78d0e219f1596209$var$re, "all"); const { chapter: chapter , verses: verses } = workspace; if (!verses) return true; const { totalOccurrences: totalOccurrences , strippedAlignment: strippedAlignment } = config; const alignments = { opened: null }; const addWrappers = ({ subtype: subtype , content: content = [] , atts: atts = {} })=>{ if (Object.keys(atts).length > 0) return { type: "wrapper", subtype: subtype, content: content, atts: atts }; return { type: "wrapper", subtype: subtype, content: content }; }; const onHoldChars = []; function pushOnHoldChars() { while(onHoldChars.length)workspace.outputContentStack[0].push(onHoldChars.shift()); } for (const word of words){ const isWord = (0, ($parcel$interopDefault($6uPpa$xregexp))).match(word, $78d0e219f1596209$var$lexingRegexes[0][2], "all")?.length; if (!isWord) { onHoldChars.push(word); continue; } workspace.currentOccurrences[word] ??= 0; workspace.currentOccurrences[word]++; const strippedKey = (position)=>[ position, word, workspace.currentOccurrences[word], totalOccurrences[chapter][verses][word] ].join("--"); const markup = strippedAlignment[chapter][verses]; let skipStartMilestone = false; const afterWord = markup[strippedKey("after")]; const beforeWord = markup[strippedKey("before")]; if (beforeWord?.length) pushOnHoldChars(); if (afterWord?.length && !alignments.opened) { afterWord.map(({ startMilestone: startMilestone })=>workspace.outputContentStack[0].push(startMilestone)); skipStartMilestone = true; } //TODO: Count number of opened alignments, to close them when there is a modified/new word in the current iteration. beforeWord?.forEach(({ payload: payload })=>{ if (payload.type !== "start_milestone") workspace.outputContentStack[0].push(payload); if (payload.type === "start_milestone" && !skipStartMilestone) { workspace.outputContentStack[0].push(payload); alignments.opened = true; } }); //TODO: Decrease number of opened alignments as they are being pushed afterWord?.forEach(({ payload: payload })=>{ alignments.opened = false; workspace.outputContentStack[0].push(payload); }); //TODO: Add as many endMilestones as there are opened in alignments.opened, and set the later to 0. if (!beforeWord?.length) { console.log(`pushing unaligned WORD: ${word}`); if (alignments.opened) { workspace.outputContentStack[0].push($78d0e219f1596209$var$endMilestone); alignments.opened = false; } pushOnHoldChars(); workspace.outputContentStack[0].push(addWrappers({ subtype: "usfm:w", content: [ word ] })); } } pushOnHoldChars(); return false; } catch (err) { console.error(err); throw err; } } } ], mark: [ { description: "mark-chapters", test: ({ context: context })=>context.sequences[0].element.subType === "chapter", action: ({ config: config , context: context , workspace: workspace , output: output })=>{ const element = context.sequences[0].element; workspace.chapter = element.atts["number"]; workspace.verses = 0;