Skip to content

Commit

Permalink
Feature 7188/update with 7 column tN tsv support (#53)
Browse files Browse the repository at this point in the history
* bump version

* split tn parsing to separate method

* adding verse range support

* added reference parser

* reduced warnings fetching verse strings

* fixes for chapter and verse to use numbers if possible, but otherwise use strings (as in the case of verse ranges).

* fix that cleaned support reference was not saved.

* bump version

* bump version
  • Loading branch information
PhotoNomad0 authored Jun 7, 2022
1 parent c6dc781 commit 738c518
Show file tree
Hide file tree
Showing 11 changed files with 21,649 additions and 22 deletions.
6,529 changes: 6,529 additions & 0 deletions __tests__/fixtures/resources/el-x-koine/bibles/ugnt/v0.11/php/1.json

Large diffs are not rendered by default.

5,641 changes: 5,641 additions & 0 deletions __tests__/fixtures/resources/el-x-koine/bibles/ugnt/v0.11/php/2.json

Large diffs are not rendered by default.

4,403 changes: 4,403 additions & 0 deletions __tests__/fixtures/resources/el-x-koine/bibles/ugnt/v0.11/php/3.json

Large diffs are not rendered by default.

4,714 changes: 4,714 additions & 0 deletions __tests__/fixtures/resources/el-x-koine/bibles/ugnt/v0.11/php/4.json

Large diffs are not rendered by default.

71 changes: 70 additions & 1 deletion __tests__/tsvToGroupdata.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,82 @@
import path from 'path-extra';
import deepEqual from 'deep-equal';
// helpers
import {
tsvToGroupData, cleanGroupId, cleanOccurrenceNoteLinks,
tsvToGroupData,
cleanGroupId,
cleanOccurrenceNoteLinks,
parseReference,
convertReference,
} from '../src/tsvToGroupData';

jest.unmock('fs-extra');

// constants
const RESOURCES_PATH = path.join(__dirname, 'fixtures', 'resources');
const ORIGINAL_BIBLE_PATH = path.join(RESOURCES_PATH, 'el-x-koine', 'bibles', 'ugnt', 'v0.11');

describe('Tests parseReference', function () {
it('Test parseReference for test cases', async () => {
const tests = [
{ ref: 'front:intro', expect: [{ chapter: 'front', verse: 'intro' }] },
{ ref: '1:intro', expect: [{ chapter: 1, verse: 'intro' }] },
{ ref: '1:1', expect: [{ chapter: 1, verse: 1 }] },
{ ref: '1:1-2', expect: [{ chapter: 1, verse: '1-2' }] },
{ ref: '1:1\u20142', expect: [{ chapter: 1, verse: '1-2' }] }, // try with EM DASH
{ ref: '1:1\u20132', expect: [{ chapter: 1, verse: '1-2' }] }, // try with EN DASH
{ ref: '1:1\u20102', expect: [{ chapter: 1, verse: '1-2' }] }, // try with HYPHEN
{ ref: '1:1\u00AD2', expect: [{ chapter: 1, verse: '1-2' }] }, // try with SOFT HYPHEN
{ ref: '1:1\u20112', expect: [{ chapter: 1, verse: '1-2' }] }, // try with NON-BREAKING HYPHEN
{ ref: '1:1,3', expect: [{ chapter: 1, verse: 1 }, { chapter: 1, verse: 3 }] },
{ ref: '1:1-2,4', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 1, verse: 4 }] },
{ ref: '1:1-2a,4', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 1, verse: 4 }] },
{ ref: '1:1b-2a,4', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 1, verse: 4 }] },
{ ref: '1:1-2,4b', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 1, verse: 4 }] },
{ ref: '1:1-2,4b,5-7a', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 1, verse: 4 }, { chapter: 1, verse: '5-7' }] },
{ ref: '1:1-2;2:4', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 2, verse: 4 }] },
{ ref: '1:1c-2b;2:4-5', expect: [{ chapter: 1, verse: '1-2' }, { chapter: 2, verse: '4-5' }] },
];

for (const test of tests) {
const ref = test.ref;
const expect_ = test.expect;
const result = parseReference(ref);

if (!deepEqual(result, expect_, { strict: true })) {
console.log(`expect ${ref} to parse to ${JSON.stringify(expect_)}`);
console.log(` but got ${JSON.stringify(result)}`);
expect(result).toEqual(expect_);
}
}
});
});

describe('Tests convertReference', function () {
it('Test convertReference for test cases', async () => {
const tests = [
{ ref: { Chapter: 'front', Verse: 'intro' }, expect: { chapter: 'front', verse: 'intro' } },
{ ref: { Chapter: 1, Verse: 'intro' }, expect: { chapter: 1, verse: 'intro' } },
{ ref: { Chapter: '1', Verse: 'intro' }, expect: { chapter: 1, verse: 'intro' } },
{ ref: { Chapter: 1, Verse: '1' }, expect: { chapter: 1, verse: 1 } },
{ ref: { Chapter: 1, Verse: 1 }, expect: { chapter: 1, verse: 1 } },
{ ref: { Chapter: 1, Verse: '1-2' }, expect: { chapter: 1, verse: '1-2' } },
{ ref: { Chapter: '1', Verse: '1-2' }, expect: { chapter: 1, verse: '1-2' } },
];

for (const test of tests) {
const ref = test.ref;
const expect_ = test.expect;
const result = convertReference(ref);

if (!deepEqual(result, expect_, { strict: true })) {
console.log(`expect ${ref} to parse to ${JSON.stringify(expect_)}`);
console.log(` but got ${JSON.stringify(result)}`);
expect(result).toEqual(expect_);
}
}
});
});

describe('tsvToGroupData():', () => {
test('Parses a book tN TSVs to an object with a lists of group ids', async () => {
const filepath = '__tests__/fixtures/tsv/en_tn_57-TIT.tsv';
Expand Down
71 changes: 71 additions & 0 deletions __tests__/wordOccurrenceHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,50 @@ function getTestResult(bookId, chapter, verse, quote) {
describe('getWordOccurrencesForQuote():', () => {
test('should generate an array of objects for an original language quote with ellipsis', () => {
const checks = [
{
// multiple ellipsis check
bookId: 'php',
chapter: 2,
verse: 1,
quote: 'εἴ τις…εἴ τι…εἴ τις…εἴ τις',
expected: [
{
'word': 'εἴ',
'occurrence': 1,
},
{
'word': 'τις',
'occurrence': 1,
},
{ 'word': '…' },
{
'word': 'εἴ',
'occurrence': 2,
},
{
'word': 'τι',
'occurrence': 1,
},
{ 'word': '…' },
{
'word': 'εἴ',
'occurrence': 3,
},
{
'word': 'τις',
'occurrence': 2,
},
{ 'word': '…' },
{
'word': 'εἴ',
'occurrence': 4,
},
{
'word': 'τις',
'occurrence': 3,
},
],
},
{
bookId: 'tit',
chapter: 1,
Expand Down Expand Up @@ -936,6 +980,33 @@ describe('getWordOccurrencesForQuote():', () => {
},
],
},
{
// figs-explicit εὐαγγελισαμένου ... τὴν πίστιν ... ὑμῶν - with verse span
bookId: '1th',
chapter: 3,
verse: '6-7',
quote: 'εὐαγγελισαμένου ... τὴν πίστιν ... ὑμῶν',
expected: [
{
word: 'εὐαγγελισαμένου',
occurrence: 1,
},
{ word: '…' },
{
word: 'τὴν',
occurrence: 1,
},
{
word: 'πίστιν',
occurrence: 1,
},
{ word: '…' },
{
word: 'ὑμῶν',
occurrence: 3,
},
],
},
];

checks.forEach(({
Expand Down
23 changes: 17 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsv-groupdata-parser",
"version": "0.10.3",
"version": "0.11.0",
"description": "Parses the translationNotes TSVs files to generate the GroupIndex and GroupData for the translationCore Desktop app.",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -37,6 +37,7 @@
"@babel/preset-env": "^7.4.5",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
"deep-equal": "1.0.1",
"eslint": "^6.3.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
Expand Down
35 changes: 33 additions & 2 deletions src/helpers/ManageResourceAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,39 @@ class ManageResource {
}

getVerseString(chapter, verse) {
const { verseObjects } = this.resource[chapter][verse];
return verseObjectsToString(verseObjects);
let verseObjects_ = [];
let isString = typeof verse === 'string';
let [start, end] = isString ? verse.split('-') : [verse];
let isRange = !!end;
let startInt = isString ? parseInt(start, 10) : verse;

if (isRange) {
let endInt = parseInt(end, 10);

if (!isNaN(startInt) && !isNaN(endInt)) {
start = startInt;
end = (endInt > startInt) ? endInt : startInt;
} else {
isRange = false;
}
} else {
if (!isNaN(startInt)) {
start = startInt;
}
}

const chapterData = this.resource[chapter];
const { verseObjects } = chapterData[start];
verseObjects_ = verseObjects;

if (isRange) {
for (let i = start + 1; i <= end; i++) {
const { verseObjects } = chapterData[i];
verseObjects_ = verseObjects_.concat(verseObjects);
}
}

return verseObjectsToString(verseObjects_);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ManageResource from './helpers/ManageResourceAPI';
export { ManageResource };
export {
tsvToGroupData,
generateGroupDataItem,
cleanGroupId,
generateGroupDataItem,
parseReference,
tsvToGroupData,
tnJsonToGroupData,
} from './tsvToGroupData';
export { generateGroupsIndex } from './groupsIndexParser';
export {
Expand Down
Loading

0 comments on commit 738c518

Please sign in to comment.