Skip to content

Commit

Permalink
Add more tests and expand app options
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgarthur committed Jan 14, 2025
1 parent 1cc2e82 commit 745ddac
Show file tree
Hide file tree
Showing 14 changed files with 2,222 additions and 46 deletions.
41 changes: 31 additions & 10 deletions e2e/OcrImporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,43 @@ afterAll(async () => {
const table = [
{
page: 'anastasimatarion_john_p0011',
deskew: true,
despeckle: false,
close: false,
},
{
page: 'heirmologion_john_p0120',
deskew: true,
despeckle: false,
close: false,
},
{
page: 'liturgica_karamanis_1990_p0257',
deskew: true,
despeckle: true,
close: false,
},
{
page: 'heirmologion_pandektis_1955_p0160',
deskew: true,
despeckle: true,
close: true,
splitLeftRight: true,
},
{
page: 'doxastarion_pringos_p0141',
deskew: true,
despeckle: true,
close: true,
},
{
page: 'vespers_sam_p0411',
},
];

test.each(table)(
'OCR $page',
async ({ page, splitLeftRight }) => {
async ({ page, splitLeftRight, deskew, despeckle, close }) => {
// Arrange
const importer = new OcrImporter();

Expand Down Expand Up @@ -79,12 +100,12 @@ test.each(table)(

// Act
if (!(await fileExists(outputPathYaml)) || !skipOcr) {
await launchOcr(
'../scripts/do_ocr.py',
imagePath,
outputPathYaml,
await launchOcr('../scripts/do_ocr.py', imagePath, outputPathYaml, {
deskew,
despeckle,
close,
splitLeftRight,
);
});
}

const elements = importer.import(
Expand All @@ -100,7 +121,7 @@ test.each(table)(

const distance = levenshteinDistance(expected, actual);

const levenShteinSimilarity =
const levenshteinSimilarity =
1 - distance.distance / Math.max(expected.length, actual.length);

const actualNoteElements = elements.filter(
Expand All @@ -124,21 +145,21 @@ test.each(table)(
report.push({
testName: expect.getState().currentTestName!,
page,
similarity: levenShteinSimilarity,
levenshteinSimilarity,
levenshteinDistance: distance.distance,
scorecard: { penalties, similarities, similarity },
});

reportFull.push({
testName: expect.getState().currentTestName!,
page,
similarity: levenShteinSimilarity,
levenshteinSimilarity,
levenshteinDistance: distance.distance,
scorecard,
});

// Assert
expect(levenShteinSimilarity).toBeGreaterThanOrEqual(
expect(levenshteinSimilarity).toBeGreaterThanOrEqual(
levenshteinDistanceThreshold,
);
},
Expand Down
Loading

0 comments on commit 745ddac

Please sign in to comment.