Deduplicate schema segment semantics validation
This commit is contained in:
@@ -251,15 +251,17 @@ func outputSchema(schemaPath string) (*jsonschema.Schema, error) {
|
||||
}
|
||||
|
||||
func validateSemantics(transcript Transcript) error {
|
||||
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||
for index, segment := range transcript.Segments {
|
||||
wantID := index + 1
|
||||
if segment.ID != wantID {
|
||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
||||
}
|
||||
if segment.End < segment.Start {
|
||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
||||
segments[index] = segmentSemantics{
|
||||
id: segment.ID,
|
||||
start: segment.Start,
|
||||
end: segment.End,
|
||||
}
|
||||
}
|
||||
if err := validateSegmentSemantics(segments); err != nil {
|
||||
return err
|
||||
}
|
||||
for index, group := range transcript.OverlapGroups {
|
||||
if group.End < group.Start {
|
||||
return fmt.Errorf("overlap_group %d has end %.3f before start %.3f", index, group.End, group.Start)
|
||||
@@ -269,26 +271,43 @@ func validateSemantics(transcript Transcript) error {
|
||||
}
|
||||
|
||||
func validateIntermediateSemantics(transcript IntermediateTranscript) error {
|
||||
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||
for index, segment := range transcript.Segments {
|
||||
wantID := index + 1
|
||||
if segment.ID != wantID {
|
||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
||||
}
|
||||
if segment.End < segment.Start {
|
||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
||||
segments[index] = segmentSemantics{
|
||||
id: segment.ID,
|
||||
start: segment.Start,
|
||||
end: segment.End,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return validateSegmentSemantics(segments)
|
||||
}
|
||||
|
||||
func validateMinimalSemantics(transcript MinimalTranscript) error {
|
||||
segments := make([]segmentSemantics, len(transcript.Segments))
|
||||
for index, segment := range transcript.Segments {
|
||||
wantID := index + 1
|
||||
if segment.ID != wantID {
|
||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.ID, wantID)
|
||||
segments[index] = segmentSemantics{
|
||||
id: segment.ID,
|
||||
start: segment.Start,
|
||||
end: segment.End,
|
||||
}
|
||||
if segment.End < segment.Start {
|
||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.End, segment.Start)
|
||||
}
|
||||
return validateSegmentSemantics(segments)
|
||||
}
|
||||
|
||||
type segmentSemantics struct {
|
||||
id int
|
||||
start float64
|
||||
end float64
|
||||
}
|
||||
|
||||
func validateSegmentSemantics(segments []segmentSemantics) error {
|
||||
for index, segment := range segments {
|
||||
wantID := index + 1
|
||||
if segment.id != wantID {
|
||||
return fmt.Errorf("segment %d has id %d; want %d", index, segment.id, wantID)
|
||||
}
|
||||
if segment.end < segment.start {
|
||||
return fmt.Errorf("segment %d has end %.3f before start %.3f", index, segment.end, segment.start)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user