Added support for a minimal JSON output schema
This commit is contained in:
@@ -57,6 +57,41 @@ func FromMerged(cfg config.Config, merged model.MergedTranscript) schema.Transcr
|
||||
}
|
||||
}
|
||||
|
||||
// MinimalFromMerged converts the internal merged transcript model into the
|
||||
// compact public serialized output contract.
|
||||
func MinimalFromMerged(cfg config.Config, merged model.MergedTranscript) schema.MinimalTranscript {
|
||||
segments := make([]schema.MinimalSegment, len(merged.Segments))
|
||||
for index, segment := range merged.Segments {
|
||||
segments[index] = schema.MinimalSegment{
|
||||
ID: segment.ID,
|
||||
Start: segment.Start,
|
||||
End: segment.End,
|
||||
Speaker: segment.Speaker,
|
||||
Text: segment.Text,
|
||||
}
|
||||
}
|
||||
|
||||
return schema.MinimalTranscript{
|
||||
Metadata: schema.MinimalMetadata{
|
||||
Application: ApplicationName,
|
||||
Version: buildinfo.Version,
|
||||
OutputSchema: config.OutputSchemaMinimal,
|
||||
},
|
||||
Segments: segments,
|
||||
}
|
||||
}
|
||||
|
||||
// SelectedFromMerged converts the internal merged transcript model into the
|
||||
// runtime-selected public output contract.
|
||||
func SelectedFromMerged(cfg config.Config, merged model.MergedTranscript) any {
|
||||
switch cfg.OutputSchema {
|
||||
case config.OutputSchemaMinimal:
|
||||
return MinimalFromMerged(cfg, merged)
|
||||
default:
|
||||
return FromMerged(cfg, merged)
|
||||
}
|
||||
}
|
||||
|
||||
func copyIntPtr(value *int) *int {
|
||||
if value == nil {
|
||||
return nil
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package artifact
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/buildinfo"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
||||
"gitea.maximumdirect.net/eric/seriatim/schema"
|
||||
)
|
||||
|
||||
func TestFromMergedUsesBuildVersion(t *testing.T) {
|
||||
@@ -20,3 +22,54 @@ func TestFromMergedUsesBuildVersion(t *testing.T) {
|
||||
t.Fatalf("version = %q, want v1.0.0-test", transcript.Metadata.Version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedDefaultsToSeriatimTranscript(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.Transcript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.Transcript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimalFromMergedEmitsOnlyMinimalShape(t *testing.T) {
|
||||
merged := model.MergedTranscript{
|
||||
Segments: []model.Segment{
|
||||
{
|
||||
ID: 1,
|
||||
Source: "input.json",
|
||||
SourceRef: "word-run:1:1:1",
|
||||
DerivedFrom: []string{"input.json#0"},
|
||||
Speaker: "Alice",
|
||||
Start: 1,
|
||||
End: 2,
|
||||
Text: "hello",
|
||||
Categories: []string{"backchannel"},
|
||||
OverlapGroupID: 1,
|
||||
},
|
||||
},
|
||||
OverlapGroups: []model.OverlapGroup{
|
||||
{ID: 1, Start: 1, End: 2, Segments: []string{"input.json#0"}, Speakers: []string{"Alice"}, Class: "unknown", Resolution: "unresolved"},
|
||||
},
|
||||
}
|
||||
|
||||
got := MinimalFromMerged(config.Config{OutputSchema: config.OutputSchemaMinimal}, merged)
|
||||
want := schema.MinimalTranscript{
|
||||
Metadata: schema.MinimalMetadata{
|
||||
Application: ApplicationName,
|
||||
Version: buildinfo.Version,
|
||||
OutputSchema: config.OutputSchemaMinimal,
|
||||
},
|
||||
Segments: []schema.MinimalSegment{
|
||||
{ID: 1, Start: 1, End: 2, Speaker: "Alice", Text: "hello"},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("minimal transcript = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedUsesMinimalWhenConfigured(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{OutputSchema: config.OutputSchemaMinimal}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.MinimalTranscript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.MinimalTranscript", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user