Add output validation against a defined JSON schema

This commit is contained in:
2026-04-27 21:27:19 -05:00
parent 8a95dba276
commit 6cb739be55
14 changed files with 638 additions and 30 deletions

View File

@@ -0,0 +1,68 @@
package artifact
import (
"gitea.maximumdirect.net/eric/seriatim/internal/config"
"gitea.maximumdirect.net/eric/seriatim/internal/model"
"gitea.maximumdirect.net/eric/seriatim/schema"
)
const (
ApplicationName = "seriatim"
Version = "dev"
)
// FromMerged converts the internal merged transcript model into the public
// serialized output contract.
func FromMerged(cfg config.Config, merged model.MergedTranscript) schema.Transcript {
segments := make([]schema.Segment, len(merged.Segments))
for index, segment := range merged.Segments {
segments[index] = schema.Segment{
ID: segment.ID,
Source: segment.Source,
SourceSegmentIndex: copyIntPtr(segment.SourceSegmentIndex),
SourceRef: segment.SourceRef,
DerivedFrom: append([]string(nil), segment.DerivedFrom...),
Speaker: segment.Speaker,
Start: segment.Start,
End: segment.End,
Text: segment.Text,
Categories: append([]string(nil), segment.Categories...),
OverlapGroupID: segment.OverlapGroupID,
}
}
overlapGroups := make([]schema.OverlapGroup, len(merged.OverlapGroups))
for index, group := range merged.OverlapGroups {
overlapGroups[index] = schema.OverlapGroup{
ID: group.ID,
Start: group.Start,
End: group.End,
Segments: append([]string(nil), group.Segments...),
Speakers: append([]string(nil), group.Speakers...),
Class: group.Class,
Resolution: group.Resolution,
}
}
return schema.Transcript{
Metadata: schema.Metadata{
Application: ApplicationName,
Version: Version,
InputReader: cfg.InputReader,
InputFiles: append([]string(nil), cfg.InputFiles...),
PreprocessingModules: append([]string(nil), cfg.PreprocessingModules...),
PostprocessingModules: append([]string(nil), cfg.PostprocessingModules...),
OutputModules: append([]string(nil), cfg.OutputModules...),
},
Segments: segments,
OverlapGroups: overlapGroups,
}
}
func copyIntPtr(value *int) *int {
if value == nil {
return nil
}
copied := *value
return &copied
}