Skip to content

Commit

Permalink
fixes for spacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotoNomad0 committed Oct 16, 2018
1 parent 739aac3 commit b40599f
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 67 deletions.
138 changes: 97 additions & 41 deletions __tests__/AlignmentHelpers.test.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
/* eslint-disable no-use-before-define */
/* eslint-env jest */
import fs from 'fs-extra';
import path from 'path';
import usfmjs from 'usfm-js';
jest.unmock('fs-extra');
import wordaligner, {VerseObjectUtils} from '../src/';
const RESOURCES = path.join('__tests__', 'fixtures', 'pivotAlignmentVerseObjects');
/**
* Reads a usfm file from the resources dir
* @param {string} filename relative path to usfm file
* @return {Object} - The read JSON object
*/
const readJSON = filename => {
const fullPath = path.join(RESOURCES, filename);
if (fs.existsSync(fullPath)) {
const json = fs.readJsonSync(fullPath);
return json;
}
console.log('File not found.');
return false;
};

/**
* Generator for testing merging of alignment into verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
*/
const mergeTest = (name = {}) => {
const json = readJSON(`${name}.json`);
expect(json).toBeTruthy();
const {alignment, verseObjects, verseString, wordBank} = json;
const output = wordaligner.merge(alignment, wordBank, verseString);
expect(output).toEqual(verseObjects);
};
/**
* Generator for testing unmerging of alignment from verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
*/
const unmergeTest = (name = {}) => {
const json = readJSON(`${name}.json`);
expect(json).toBeTruthy();
const {verseObjects, alignment, wordBank, alignedVerseString} = json;
const output = wordaligner.unmerge(verseObjects, alignedVerseString);
expect(output).toEqual({alignment, wordBank});
};

describe("Merge Alignment into Verse Objects", () => {
it('handles one to one', () => {
Expand Down Expand Up @@ -161,6 +126,15 @@ describe("UnMerge Alignment from Verse Objects", () => {
});
});

describe("export USFM3 from Verse Objects", () => {
it('handles acts-1-11', () => {
exportTest('acts-1-11');
});
it('handles acts 1-4', () => {
exportTest('acts-1-4');
});
});

describe('wordaligner.generateBlankAlignments', () => {
const createEmptyAlignment = function(verseObjects) {
let wordList = VerseObjectUtils.getWordList(verseObjects);
Expand Down Expand Up @@ -248,8 +222,90 @@ describe('wordaligner.generateWordBank', () => {
// then
expect(results).toEqual(wordBank);
});

//
// helpers
//
});

//
// helpers
//

/**
* Reads a json file from the resources dir
* @param {string} filename relative path to usfm file
* @return {Object} - The read JSON object
*/
const readJSON = filename => {
const fullPath = path.join(RESOURCES, filename);
if (fs.existsSync(fullPath)) {
const json = fs.readJsonSync(fullPath);
return json;
}
console.log('File not found.');
return false;
};

/**
* Reads a usfm file from the resources dir
* @param {string} filename relative path to usfm file
* @return {Object} - The read JSON object
*/
const readUSFM = filename => {
const fullPath = path.join(RESOURCES, filename);
if (fs.existsSync(fullPath)) {
const usfm = fs.readFileSync(fullPath, 'UTF-8').toString();
return usfm;
}
console.log('File not found.');
return false;
};

/**
* Generator for testing merging of alignment into verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
*/
const mergeTest = (name = {}) => {
const json = readJSON(`${name}.json`);
expect(json).toBeTruthy();
const {alignment, verseObjects, verseString, wordBank} = json;
const output = wordaligner.merge(alignment, wordBank, verseString);
expect(output).toEqual(verseObjects);
};

/**
* Generator for testing unmerging of alignment from verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
*/
const unmergeTest = (name = {}) => {
const json = readJSON(`${name}.json`);
expect(json).toBeTruthy();
const {verseObjects, alignment, wordBank, alignedVerseString} = json;
const output = wordaligner.unmerge(verseObjects, alignedVerseString);
expect(output).toEqual({alignment, wordBank});
};

/**
* Generator for testing merging of alignment into verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
*/
const exportTest = (name = {}) => {
const json = readJSON(`${name}.json`);
expect(json).toBeTruthy();
const expectedUsfm = readUSFM(`${name}.usfm`);
expect(expectedUsfm).toBeTruthy();
const {alignment, verseString, wordBank} = json;
const output = wordaligner.merge(alignment, wordBank, verseString);
const outputData = {
chapters: {},
headers: [],
verses: {
1: output
}
};
let usfm = usfmjs.toUSFM(outputData, {chunk: true});
const split = usfm.split("\\v 1");
usfm = split.length > 1 ? split[1] : "";
if (usfm.substr(0, 1) === ' ') {
usfm = usfm.substr(1);
}
expect(usfm).toEqual(expectedUsfm);
};

4 changes: 2 additions & 2 deletions __tests__/fixtures/pivotAlignmentVerseObjects/acts-1-11.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"alignedVerseString": "οἳ καὶ εἶπαν, “ ἄνδρες, Γαλιλαῖοι, τί ἑστήκατε βλέποντες εἰς τὸν οὐρανόν? οὗτος ὁ Ἰησοῦς ὁ ἀναλημφθεὶς ἀφ’ ὑμῶν εἰς τὸν οὐρανὸν, οὕτως ἐλεύσεται ὃν τρόπον ἐθεάσασθε αὐτὸν πορευόμενον εἰς τὸν οὐρανόν.”",
"verseString": "And they said,\"Men of Galilee, why do you stand looking into heaven? This Jesus who has been taken up from you into heaven, will likewise return in the same manner as you saw him going into heaven.\"\\p",
"verseString": "And they said,\"Men of Galilee, why do you stand looking into heaven? This Jesus who has been taken up from you into heaven, will likewise return in the same manner as you saw him going into heaven.\"\n\\p",
"alignment": [
{
"topWords": [
Expand Down Expand Up @@ -1273,7 +1273,7 @@
"type": "text"
},
{
"text": "\"",
"text": "\"\n",
"type": "text"
},
{
Expand Down
104 changes: 104 additions & 0 deletions __tests__/fixtures/pivotAlignmentVerseObjects/acts-1-11.usfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

\zaln-s | x-strong="G25320" x-lemma="καί" x-morph="Gr,D,,,,,,,,," x-occurrence="1" x-occurrences="1" x-content="καὶ"
\w And|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G37390" x-lemma="ὅς" x-morph="Gr,RR,,,,NMP," x-occurrence="1" x-occurrences="1" x-content="οἳ"
\w they|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G30040" x-lemma="λέγω" x-morph="Gr,V,IAA3,,P," x-occurrence="1" x-occurrences="1" x-content="εἶπαν"
\w said|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*,"
\zaln-s | x-strong="G04350" x-lemma="ἀνήρ" x-morph="Gr,N,,,,,VMP," x-occurrence="1" x-occurrences="1" x-content="ἄνδρες"
\w Men|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G10570" x-lemma="Γαλιλαῖος" x-morph="Gr,NS,,,,VMP," x-occurrence="1" x-occurrences="1" x-content="Γαλιλαῖοι"
\w of|x-occurrence="1" x-occurrences="1"\w*
\w Galilee|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*,
\zaln-s | x-strong="G51010" x-lemma="τίς" x-morph="Gr,RT,,,,ANS," x-occurrence="1" x-occurrences="1" x-content="τί"
\w why|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G24760" x-lemma="ἵστημι" x-morph="Gr,V,IEA2,,P," x-occurrence="1" x-occurrences="1" x-content="ἑστήκατε"
\w do|x-occurrence="1" x-occurrences="1"\w*
\w you|x-occurrence="1" x-occurrences="3"\w*
\w stand|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G09910" x-lemma="βλέπω" x-morph="Gr,V,PPA,NMP," x-occurrence="1" x-occurrences="1" x-content="βλέποντες"
\w looking|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G15190" x-lemma="εἰς" x-morph="Gr,P,,,,,A,,," x-occurrence="1" x-occurrences="3" x-content="εἰς"
\w into|x-occurrence="1" x-occurrences="3"\w*
\zaln-e\*
\zaln-s | x-strong="G35880" x-lemma="ὁ" x-morph="Gr,EA,,,,AMS," x-occurrence="1" x-occurrences="3" x-content="τὸν"
\zaln-s | x-strong="G37720" x-lemma="οὐρανός" x-morph="Gr,N,,,,,AMS," x-occurrence="1" x-occurrences="2" x-content="οὐρανόν"
\w heaven|x-occurrence="1" x-occurrences="3"\w*
\zaln-e\*
\zaln-e\*?
\zaln-s | x-strong="G37780" x-lemma="οὗτος" x-morph="Gr,ED,,,,NMS," x-occurrence="1" x-occurrences="1" x-content="οὗτος"
\w This|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G35880" x-lemma="ὁ" x-morph="Gr,EA,,,,NMS," x-occurrence="1" x-occurrences="2" x-content="ὁ"
\zaln-s | x-strong="G24240" x-lemma="Ἰησοῦς" x-morph="Gr,N,,,,,NMS," x-occurrence="1" x-occurrences="1" x-content="Ἰησοῦς"
\w Jesus|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-e\*
\zaln-s | x-strong="G35880" x-lemma="ὁ" x-morph="Gr,RD,,,,NMS," x-occurrence="2" x-occurrences="2" x-content="ὁ"
\zaln-s | x-strong="G03530" x-lemma="ἀναλαμβάνω" x-morph="Gr,V,PAP,NMS," x-occurrence="1" x-occurrences="1" x-content="ἀναλημφθεὶς"
\w who|x-occurrence="1" x-occurrences="1"\w*
\w has|x-occurrence="1" x-occurrences="1"\w*
\w been|x-occurrence="1" x-occurrences="1"\w*
\w taken|x-occurrence="1" x-occurrences="1"\w*
\w up|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-e\*
\zaln-s | x-strong="G05750" x-lemma="ἀπό" x-morph="Gr,P,,,,,G,,," x-occurrence="1" x-occurrences="1" x-content="ἀφ’"
\w from|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G47710" x-lemma="σύ" x-morph="Gr,RP,,,2G,P," x-occurrence="1" x-occurrences="1" x-content="ὑμῶν"
\w you|x-occurrence="2" x-occurrences="3"\w*
\zaln-e\*
\zaln-s | x-strong="G15190" x-lemma="εἰς" x-morph="Gr,P,,,,,A,,," x-occurrence="2" x-occurrences="3" x-content="εἰς"
\w into|x-occurrence="2" x-occurrences="3"\w*
\zaln-e\*
\zaln-s | x-strong="G35880" x-lemma="ὁ" x-morph="Gr,EA,,,,AMS," x-occurrence="2" x-occurrences="3" x-content="τὸν"
\zaln-s | x-strong="G37720" x-lemma="οὐρανός" x-morph="Gr,N,,,,,AMS," x-occurrence="1" x-occurrences="1" x-content="οὐρανὸν"
\w heaven|x-occurrence="2" x-occurrences="3"\w*
\zaln-e\*
\zaln-e\*,
\zaln-s | x-strong="G20640" x-lemma="ἔρχομαι" x-morph="Gr,V,IFM3,,S," x-occurrence="1" x-occurrences="1" x-content="ἐλεύσεται"
\w will|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G37790" x-lemma="οὕτως" x-morph="Gr,D,,,,,,,,," x-occurrence="1" x-occurrences="1" x-content="οὕτως"
\w likewise|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G20640" x-lemma="ἔρχομαι" x-morph="Gr,V,IFM3,,S," x-occurrence="1" x-occurrences="1" x-content="ἐλεύσεται"
\w return|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G37390" x-lemma="ὅς" x-morph="Gr,ER,,,,AMS," x-occurrence="1" x-occurrences="1" x-content="ὃν"
\w in|x-occurrence="1" x-occurrences="1"\w*
\w the|x-occurrence="1" x-occurrences="1"\w*
\w same|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G51580" x-lemma="τρόπος" x-morph="Gr,N,,,,,AMS," x-occurrence="1" x-occurrences="1" x-content="τρόπον"
\w manner|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G23000" x-lemma="θεάομαι" x-morph="Gr,V,IAM2,,P," x-occurrence="1" x-occurrences="1" x-content="ἐθεάσασθε"
\w as|x-occurrence="1" x-occurrences="1"\w*
\w you|x-occurrence="3" x-occurrences="3"\w*
\w saw|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G08460" x-lemma="αὐτός" x-morph="Gr,RP,,,3AMS," x-occurrence="1" x-occurrences="1" x-content="αὐτὸν"
\w him|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G41980" x-lemma="πορεύω" x-morph="Gr,V,PPM,AMS," x-occurrence="1" x-occurrences="1" x-content="πορευόμενον"
\w going|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-strong="G15190" x-lemma="εἰς" x-morph="Gr,P,,,,,A,,," x-occurrence="3" x-occurrences="3" x-content="εἰς"
\w into|x-occurrence="3" x-occurrences="3"\w*
\zaln-e\*
\zaln-s | x-strong="G35880" x-lemma="ὁ" x-morph="Gr,EA,,,,AMS," x-occurrence="3" x-occurrences="3" x-content="τὸν"
\zaln-s | x-strong="G37720" x-lemma="οὐρανός" x-morph="Gr,N,,,,,AMS," x-occurrence="2" x-occurrences="2" x-content="οὐρανόν"
\w heaven|x-occurrence="3" x-occurrences="3"\w*
\zaln-e\*
\zaln-e\*."
\p
68 changes: 68 additions & 0 deletions __tests__/fixtures/pivotAlignmentVerseObjects/acts-1-4.usfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

\zaln-s | x-lemma="καί" x-morph="Gr,CC,,,,,,,," x-occurrence="1" x-occurrences="1" x-strong="G25320" x-content="καὶ"
\w When|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="συναλίζω" x-morph="Gr,V,PPM,NMS," x-occurrence="1" x-occurrences="1" x-strong="G48710" x-content="συναλιζόμενος"
\w he|x-occurrence="1" x-occurrences="3"\w*
\w was|x-occurrence="1" x-occurrences="1"\w*
\w meeting|x-occurrence="1" x-occurrences="1"\w*
\w together|x-occurrence="1" x-occurrences="1"\w*
\w with|x-occurrence="1" x-occurrences="1"\w*
\w them|x-occurrence="1" x-occurrences="2"\w*
\zaln-e\*,
\zaln-s | x-lemma="παραγγέλλω" x-morph="Gr,V,IAA3,,S," x-occurrence="1" x-occurrences="1" x-strong="G38530" x-content="παρήγγειλεν"
\w he|x-occurrence="2" x-occurrences="3"\w*
\w commanded|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="αὐτός" x-morph="Gr,RP,,,3DMP," x-occurrence="1" x-occurrences="1" x-strong="G08460" x-content="αὐτοῖς"
\w them|x-occurrence="2" x-occurrences="2"\w*
\zaln-e\*
\zaln-s | x-lemma="μή" x-morph="Gr,DO,,,,,,,," x-occurrence="1" x-occurrences="1" x-strong="G33610" x-content="μὴ"
\w not|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="χωρίζω" x-morph="Gr,V,NPP,,,,," x-occurrence="1" x-occurrences="1" x-strong="G55630" x-content="χωρίζεσθαι"
\w to|x-occurrence="1" x-occurrences="2"\w*
\w leave|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="ἀπό" x-morph="Gr,P,,,,,G,,," x-occurrence="1" x-occurrences="1" x-strong="G05750" x-content="ἀπὸ"
\zaln-s | x-lemma="Ἱεροσόλυμα" x-morph="Gr,N,,,,,GNP," x-occurrence="1" x-occurrences="1" x-strong="G24140" x-content="Ἱεροσολύμων"
\w Jerusalem|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-e\*,
\zaln-s | x-lemma="ἀλλά" x-morph="Gr,CO,,,,,,,," x-occurrence="1" x-occurrences="1" x-strong="G02350" x-content="ἀλλὰ"
\w but|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="περιμένω" x-morph="Gr,V,NPA,,,,," x-occurrence="1" x-occurrences="1" x-strong="G40370" x-content="περιμένειν"
\w to|x-occurrence="2" x-occurrences="2"\w*
\w wait|x-occurrence="1" x-occurrences="1"\w*
\w for|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="ὁ" x-morph="Gr,EA,,,,AFS," x-occurrence="1" x-occurrences="1" x-strong="G35880" x-content="τὴν"
\w the|x-occurrence="1" x-occurrences="2"\w*
\zaln-e\*
\zaln-s | x-lemma="ἐπαγγελία" x-morph="Gr,N,,,,,AFS," x-occurrence="1" x-occurrences="1" x-strong="G18600" x-content="ἐπαγγελίαν"
\w promise|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="ὁ" x-morph="Gr,EA,,,,GMS," x-occurrence="1" x-occurrences="1" x-strong="G35880" x-content="τοῦ"
\w of|x-occurrence="1" x-occurrences="1"\w*
\w the|x-occurrence="2" x-occurrences="2"\w*
\zaln-e\*
\zaln-s | x-lemma="πατήρ" x-morph="Gr,N,,,,,GMS," x-occurrence="1" x-occurrences="1" x-strong="G39620" x-content="Πατρὸς"
\w Father|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*,
\zaln-s | x-lemma="ὅς" x-morph="Gr,RR,,,,AFS," x-occurrence="1" x-occurrences="1" x-strong="G37390" x-content="ἣν"
\w about|x-occurrence="1" x-occurrences="1"\w*
\w which|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*,
\zaln-s | x-lemma="ὅς" x-morph="Gr,RR,,,,AFS," x-occurrence="1" x-occurrences="1" x-strong="G37390" x-content="ἣν"
\w he|x-occurrence="3" x-occurrences="3"\w*
\w said|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*,\qt-s |who="Jesus"\*"
\zaln-s | x-lemma="ἐγώ" x-morph="Gr,RP,,,1G,S," x-occurrence="1" x-occurrences="1" x-strong="G14730" x-content="μου"
\w You|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
\zaln-s | x-lemma="ἀκούω" x-morph="Gr,V,IAA2,,P," x-occurrence="1" x-occurrences="1" x-strong="G01910" x-content="ἠκούσατέ"
\w heard|x-occurrence="1" x-occurrences="1"\w*
\w from|x-occurrence="1" x-occurrences="1"\w*
\w me|x-occurrence="1" x-occurrences="1"\w*
\zaln-e\*
2 changes: 1 addition & 1 deletion __tests__/fixtures/pivotAlignmentVerseObjects/matt1-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
},
{
"type": "text",
"text": "."
"text": ". "
},
{
"tag": "f",
Expand Down
8 changes: 6 additions & 2 deletions __tests__/fixtures/pivotAlignmentVerseObjects/tit1-12.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"alignedVerseString": "εἶπέν τις ἐξ αὐτῶν, ἴδιος αὐτῶν προφήτης, “Κρῆτες ἀεὶ ψεῦσται, κακὰ θηρία, γαστέρες ἀργαί.”",
"verseString": "One of their own prophets has said, \"Cretans are always liars, evil beasts, lazy gluttons.\"",
"verseString": "One of their own prophets has said, \"Cretans are always liars, evil beasts, lazy gluttons.\"\n\\p",
"verseObjects": [
{
"children": [
Expand Down Expand Up @@ -312,8 +312,12 @@
"type": "text"
},
{
"text": "\"",
"text": "\"\n",
"type": "text"
},
{
"tag": "p",
"type": "paragraph"
}
],
"alignment": [
Expand Down
Loading

0 comments on commit b40599f

Please sign in to comment.