UNPKG

kathairo

Version:

A CLI utility for processing USFM.

140 lines (120 loc) 2.62 kB
import { Proskomma } from "proskomma-core"; import { log } from "./logger.js"; export async function loadProskomma(files, lang, abbrev, quiet) { const pk = new Proskomma(); files.forEach((file) => { if (!file.isValid) { log('info', `${file.path} contains invalid USFM. Skipping...`); return } try { pk.importDocument( { lang: lang, abbr: abbrev, }, 'usfm', file.content, ); } catch (error) { log('error', "Encountered an error when parsing file."); log('error', error); log('error', '\n Sample from Erroneous file :: \n'); log('error', file.content.toString('utf8').slice(0, 200)); log('error', '\n End sample. \n'); } }) return pk } const runQuery = async (pk, query) => { return await pk.gqlQuery(query); }; export const getDocuments = async (pk) => { return await runQuery(pk, query7); }; // const book = "1CH" // const chapter = "1" // const query = `{ documents { mainText } }`; // const query2 = `{ // docSets { // document(bookCode: ${book}) { // cv(chapterVerses: "1") { // text // } // } // } // }` // const query3 = `{ // docSets { // id // document(bookCode:"${book}") { // cv(chapterVerses:"1") { // scopeLabels(startsWith:["chapter", "verses"]) // text // } // } // } // }`; // const query35 = `{ // docSets { // id // documents { // bookCode: header( id:"bookCode" ) // cv(chapterVerses:"1") { // scopeLabels(startsWith:["chapter", "verses"]) // text // } // } // } // }`; // const query4 = `{ // docSets { // id // documents { id, cvNavigation(chapter: "1", verse: "1") { id } } // } // }` // const query5 = `{ // documents { // id // bookCode // mainSequence { // blocks { // bg { chapter verse } // items { // type // subType // payload // } // } // } // } // }` // const query6 = `{ // docSets { // documents { // id // mainSequence { // blocks { // text // scopeLabels(startsWith:["chapter", "verse"]) // } // } // } // } // }` const query7 = `{ docSets { documents { id bookCode: header( id:"bookCode" ) mainSequence { blocks { itemGroups(byScopes:["chapter/", "verses/"]) { scopeLabels(startsWith:["chapter/", "verse/"]) text } } } } } }`