-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle glossary link entries * Minor changes * Lint format issues * Eliminate glossary reference in ScriptureViewSophria and general cleanup * Check in isBibleBook * Check in tests for isBibleBook * Fix tests and commit changes to make tests run independently of installed application * Fix lint check * Fix test imports * Added comments
- Loading branch information
1 parent
e463432
commit 1e7e8f7
Showing
18 changed files
with
17,878 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { describe, expect, beforeEach, it, test } from 'vitest'; | ||
import { readFile, readFileSync, writeFile, writeFileSync, mkdirSync, existsSync } from 'fs'; | ||
import path from 'path'; | ||
import { verifyGlossaryEntries } from './verifyGlossaryEntries'; | ||
|
||
describe('verifyGlossaryEntries', () => { | ||
// Tests using Genesis 1: 1 & 2 | ||
const data = readFileSync(path.join('test_data', 'books', 'C01', '01GENengWEBbd.usfm'), 'utf8'); | ||
describe('with all entries in the glossary', () => { | ||
let modifiedContent: string; | ||
beforeEach(() => { | ||
const glossary = ['excess', 'serpent', 'middle', 'subtle', 'tree', 'extra']; | ||
modifiedContent = verifyGlossaryEntries(data, glossary); | ||
}); | ||
it('leaves in place simple entry', () => { | ||
expect(modifiedContent).toContain('Now the \\w serpent\\w* was more'); | ||
}); | ||
it('leaves in place entry with an extra space', () => { | ||
expect(modifiedContent).toContain('more \\w subtle \\w*than any animal'); | ||
}); | ||
it('leaves in place entry using lemma', () => { | ||
expect(modifiedContent).toContain( | ||
'We may eat fruit from the \\w trees|tree \\w* of the garden' | ||
); | ||
}); | ||
}); | ||
describe('with all entries case mismatch', () => { | ||
let modifiedContent: string; | ||
beforeEach(() => { | ||
const glossary = ['Excess', 'Serpent', 'Middle', 'Subtle', 'Tree', 'Extra']; | ||
modifiedContent = verifyGlossaryEntries(data, glossary); | ||
}); | ||
it('leaves in place simple entry', () => { | ||
expect(modifiedContent).toContain('Now the \\w serpent\\w* was more'); | ||
}); | ||
it('leaves in place entry with an extra space', () => { | ||
expect(modifiedContent).toContain('more \\w subtle \\w*than any animal'); | ||
}); | ||
it('leaves in place entry using lemma', () => { | ||
expect(modifiedContent).toContain( | ||
'We may eat fruit from the \\w trees|tree \\w* of the garden' | ||
); | ||
}); | ||
}); | ||
describe('with one mismatch', () => { | ||
let modifiedContent: string; | ||
beforeEach(() => { | ||
const glossary = ['excess', 'serpent', 'middle', 'subtle', 'trees', 'extra']; | ||
modifiedContent = verifyGlossaryEntries(data, glossary); | ||
}); | ||
it('leaves in place simple entry', () => { | ||
expect(modifiedContent).toContain('Now the \\w serpent\\w* was more'); | ||
}); | ||
it('leaves in place entry with an extra space', () => { | ||
expect(modifiedContent).toContain('more \\w subtle \\w*than any animal'); | ||
}); | ||
it('removes when matches first but not lemma', () => { | ||
expect(modifiedContent).toContain('We may eat fruit from the trees of the garden'); | ||
}); | ||
}); | ||
describe('with missing entries in the glossary', () => { | ||
let modifiedContent: string; | ||
beforeEach(() => { | ||
const glossary = ['excess', 'serpent', 'more', 'middle', 'tree', 'extra']; | ||
modifiedContent = verifyGlossaryEntries(data, glossary); | ||
}); | ||
it('leaves in place simple entry', () => { | ||
expect(modifiedContent).toContain('Now the \\w serpent\\w* was more'); | ||
}); | ||
it('removes mismatched entry', () => { | ||
expect(modifiedContent).toContain('more subtle than any animal'); | ||
}); | ||
it('leaves in place entry using lemma', () => { | ||
expect(modifiedContent).toContain( | ||
'We may eat fruit from the \\w trees|tree \\w* of the garden' | ||
); | ||
}); | ||
}); | ||
describe('with empty glossary', () => { | ||
let modifiedContent: string; | ||
beforeEach(() => { | ||
const glossary: string[] = []; | ||
modifiedContent = verifyGlossaryEntries(data, glossary); | ||
}); | ||
it('removes simple entry', () => { | ||
expect(modifiedContent).toContain('Now the serpent was more'); | ||
}); | ||
it('removes entry with an extra space', () => { | ||
expect(modifiedContent).toContain('more subtle than any animal'); | ||
}); | ||
it('removes entry using lemma', () => { | ||
expect(modifiedContent).toContain('We may eat fruit from the trees of the garden'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ciEquals } from './stringUtils'; | ||
|
||
export function verifyGlossaryEntries(content: string, glossary: string[]): string { | ||
// Regular expression pattern | ||
const regex = /\\w\s*([^\\]+)\s*\\w\*/; | ||
let result: string = ''; | ||
result = content; | ||
const sb = []; | ||
let inputString = content; | ||
let match; | ||
// Loop through all matches | ||
while ((match = regex.exec(inputString)) !== null) { | ||
// Append text segment with 1st part of string | ||
sb.push(inputString.substring(0, match.index)); | ||
// match[1] contains the text between \k and \k* | ||
const matchWord = entryToMatch(match[1]); | ||
const originalEntry: string = match[0]; | ||
const textOnlyEntry: string = textFromMatch(match[1]); | ||
let matchFound = false; | ||
glossary.every((glossaryEntry) => { | ||
if (ciEquals(glossaryEntry.trim(), matchWord)) { | ||
matchFound = true; | ||
return false; | ||
} | ||
return true; | ||
}); | ||
if (matchFound) { | ||
sb.push(originalEntry); | ||
} else { | ||
sb.push(textFromMatch(textOnlyEntry)); | ||
} | ||
const oldLength = inputString.length; | ||
inputString = inputString.substring(match.index + match[0].length); | ||
} | ||
sb.push(inputString); | ||
result = sb.join(''); | ||
return result; | ||
} | ||
function entryToMatch(match: string): string { | ||
let result: string; | ||
const parts = match.split('|'); | ||
if (parts.length > 1) { | ||
result = parts[1].trim(); | ||
} else { | ||
result = parts[0].trim(); | ||
} | ||
return result; | ||
} | ||
function textFromMatch(match: string): string { | ||
const parts = match.split('|'); | ||
return parts[0]; | ||
} |
Oops, something went wrong.