Added a new JSON public schema as the default output artifact
This commit is contained in:
@@ -15,6 +15,7 @@ var schemaFS embed.FS
|
||||
|
||||
const (
|
||||
outputSchemaPath = "output.schema.json"
|
||||
defaultOutputSchemaPath = "default-output.schema.json"
|
||||
minimalOutputSchemaPath = "minimal-output.schema.json"
|
||||
)
|
||||
|
||||
@@ -24,13 +25,19 @@ var (
|
||||
compileMu sync.Mutex
|
||||
)
|
||||
|
||||
// Transcript is seriatim's public JSON output contract.
|
||||
// Transcript is seriatim's full public JSON output contract.
|
||||
type Transcript struct {
|
||||
Metadata Metadata `json:"metadata"`
|
||||
Segments []Segment `json:"segments"`
|
||||
OverlapGroups []OverlapGroup `json:"overlap_groups"`
|
||||
}
|
||||
|
||||
// DefaultTranscript is seriatim's default public JSON output contract.
|
||||
type DefaultTranscript struct {
|
||||
Metadata DefaultMetadata `json:"metadata"`
|
||||
Segments []DefaultSegment `json:"segments"`
|
||||
}
|
||||
|
||||
// MinimalTranscript is seriatim's compact public JSON output contract.
|
||||
type MinimalTranscript struct {
|
||||
Metadata MinimalMetadata `json:"metadata"`
|
||||
@@ -48,6 +55,13 @@ type Metadata struct {
|
||||
OutputModules []string `json:"output_modules"`
|
||||
}
|
||||
|
||||
// DefaultMetadata records default artifact identity.
|
||||
type DefaultMetadata struct {
|
||||
Application string `json:"application"`
|
||||
Version string `json:"version"`
|
||||
OutputSchema string `json:"output_schema"`
|
||||
}
|
||||
|
||||
// MinimalMetadata records minimal artifact identity.
|
||||
type MinimalMetadata struct {
|
||||
Application string `json:"application"`
|
||||
@@ -70,6 +84,17 @@ type Segment struct {
|
||||
OverlapGroupID int `json:"overlap_group_id,omitempty"`
|
||||
}
|
||||
|
||||
// DefaultSegment is the compact public transcript segment shape with
|
||||
// categories.
|
||||
type DefaultSegment struct {
|
||||
ID int `json:"id"`
|
||||
Start float64 `json:"start"`
|
||||
End float64 `json:"end"`
|
||||
Speaker string `json:"speaker"`
|
||||
Text string `json:"text"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
}
|
||||
|
||||
// MinimalSegment is the compact public transcript segment shape.
|
||||
type MinimalSegment struct {
|
||||
ID int `json:"id"`
|
||||
@@ -104,6 +129,20 @@ func ValidateTranscript(transcript Transcript) error {
|
||||
return ValidateJSON(data)
|
||||
}
|
||||
|
||||
// ValidateDefaultTranscript validates the default transcript against the
|
||||
// default JSON schema and seriatim-specific semantic rules.
|
||||
func ValidateDefaultTranscript(transcript DefaultTranscript) error {
|
||||
if err := validateDefaultSemantics(transcript); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := json.Marshal(transcript)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal default transcript for schema validation: %w", err)
|
||||
}
|
||||
return ValidateDefaultJSON(data)
|
||||
}
|
||||
|
||||
// ValidateMinimalTranscript validates a minimal transcript against the minimal
|
||||
// JSON schema and seriatim-specific semantic rules.
|
||||
func ValidateMinimalTranscript(transcript MinimalTranscript) error {
|
||||
@@ -123,6 +162,12 @@ func ValidateJSON(data []byte) error {
|
||||
return validateJSONWithSchema(data, outputSchemaPath)
|
||||
}
|
||||
|
||||
// ValidateDefaultJSON validates serialized default output JSON against the
|
||||
// default public schema.
|
||||
func ValidateDefaultJSON(data []byte) error {
|
||||
return validateJSONWithSchema(data, defaultOutputSchemaPath)
|
||||
}
|
||||
|
||||
// ValidateMinimalJSON validates serialized minimal output JSON against the
|
||||
// minimal public schema.
|
||||
func ValidateMinimalJSON(data []byte) error {
|
||||
@@ -200,6 +245,19 @@ func validateSemantics(transcript Transcript) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDefaultSemantics(transcript DefaultTranscript) error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMinimalSemantics(transcript MinimalTranscript) error {
|
||||
for index, segment := range transcript.Segments {
|
||||
wantID := index + 1
|
||||
|
||||
Reference in New Issue
Block a user