unfoldingWord / gateway-admin

The gatewayAdmin app gives GL team administrators an easier way to manage files and repos on DCS.
MIT License
1 stars 2 forks source link

Design and define the logic for calculating the GL quote #167

Open mandolyte opened 1 year ago

mandolyte commented 1 year ago

Sketched out the essentials for the quote package (the single word use case only): Where values are mentioned, they come from the TN for 1PE 1:1, id=g6b4. This use case is for a single original word, not phrases or ellipses.

Prerequisites

Notable Conditions

Inputs

Returns

An object with the following properties:

mandolyte commented 1 year ago

Notes

Below find the USFM and JSON for the English UST for the example reference (1PE 1:1).

The process is roughly as follows:

  1. find the chapter and verse (remember it may be inside a verse span!)
  2. loop thru the verse objects to find the zaln tags
  3. for the tag with the "content" that matches the original word (in this case Πέτρος) and the occurrence number, then...
  4. create the return object, which would be something like this:
    {
    content: "I am Peter",
    occurrence: "1"
    }

Here is the USFM from 1PE 1:1.

\v 1 {\zaln-s \|x-strong="G40740" x-lemma="πέτρος" x-morph="Gr,N,,,,,NMS," x-occurrence="1" x-occurrences="1" x-content="Πέτρος"\*\w I\|x-occurrence="1" x-occurrences="3"\w*
\w am\|x-occurrence="1" x-occurrences="3"\w*}
\w Peter\|x-occurrence="1" x-occurrences="1"\w*\zaln-e\*,

Here is the corresponding JSON:


{
    "1": {
        "1": {
            "verseObjects": [
                {
                    "type": "text",
                    "text": "{"
                },
                {
                    "tag": "zaln",
                    "type": "milestone",
                    "strong": "G40740",
                    "lemma": "πέτρος",
                    "morph": "Gr,N,,,,,NMS,",
                    "occurrence": "1",
                    "occurrences": "1",
                    "content": "Πέτρος",
                    "children": [
                        {
                            "text": "I",
                            "tag": "w",
                            "type": "word",
                            "occurrence": "1",
                            "occurrences": "3"
                        },
                        {
                            "type": "text",
                            "text": " "
                        },
                        {
                            "text": "am",
                            "tag": "w",
                            "type": "word",
                            "occurrence": "1",
                            "occurrences": "3"
                        },
                        {
                            "type": "text",
                            "text": "} "
                        },
                        {
                            "text": "Peter",
                            "tag": "w",
                            "type": "word",
                            "occurrence": "1",
                            "occurrences": "1"
                        }
                    ],
                    "endTag": "zaln-e\\*"
mandolyte commented 1 year ago

In case it is useful, here is a little node.js script to convert USFM to JSON:

import usfmjs from 'usfm-js';
import { readFile, writeFile } from 'fs';

let testinput = '1pe_usfm.txt';
let jsoninput;
let chapters;

readFile(testinput, (err, data) => {
    if (err) throw err;

    let s = ""+data;
    jsoninput = usfmjs.toJSON(s);
    chapters = jsoninput.chapters;
    writeFile(testinput+".json",JSON.stringify(chapters, undefined, 4),
        function(err) {
            if (err) {
                return console.log(err);
            }
        }
    );

});