Skip to content

Commit

Permalink
Update STJ validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniv-golan committed Nov 1, 2024
1 parent 621f3bc commit fb9caa6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/javascript/test_stj_validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ test('Invalid STJ file with invalid word_timing_mode fails validation', (done) =
});

test('Invalid STJ file with zero-duration word without flag fails validation', (done) => {
runValidatorTest(
'zero_duration_word_without_flag.stj.json',
"Zero-duration word at 1 without 'word_duration' set to 'zero'",
done
);
const stjFile = path.join(__dirname, 'data', 'zero_duration_word_without_flag.stj.json');
exec(`node ${validator} ${stjFile} ${schemaFile}`, (error, stdout, stderr) => {
expect(error).not.toBeNull();
expect(stderr).toContain('Word "Zero" has zero duration (start: 1, end: 1)');
done();
});
});

test('Invalid STJ file with invalid confidence scores fails validation', (done) => {
Expand Down
18 changes: 18 additions & 0 deletions tools/javascript/stj-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function validateStjData(data) {
validateLanguageCodes(data);
validateSegments(data);
validateSpeakersAndStyles(data);
validateWordTimings(data.transcript);
}

function validateLanguageCodes(data) {
Expand Down Expand Up @@ -259,6 +260,23 @@ function validateWords(segment, segmentIndex) {
}
}

function validateWordTimings(transcript) {
const segments = transcript.segments || [];

for (const segment of segments) {
const words = segment.words || [];

for (const word of words) {
// Check for zero duration words
if (word.start === word.end) {
throw new Error(`Word "${word.text}" has zero duration (start: ${word.start}, end: ${word.end})`);
}

// ... other word timing validations ...
}
}
}

// Add these utility functions at the top level
function validateTimeValue(time, context) {
// Check basic type and format
Expand Down

0 comments on commit fb9caa6

Please sign in to comment.