Keep transcript decoding and encoding on typed data
This commit is contained in:
@@ -45,7 +45,7 @@ func ApplyProposals(
|
||||
policy ReplacementPolicy,
|
||||
allowsChange func(before, after string) bool,
|
||||
) ApplyResult {
|
||||
working := cloneTranscript(transcript)
|
||||
working := transcript.Clone()
|
||||
ordered := sortProposalsByIndex(proposals)
|
||||
|
||||
applied := make([]AppliedChange, 0, len(ordered))
|
||||
@@ -104,32 +104,6 @@ func sortProposalsByIndex(proposals []EnrichedCorrectionProposal) []EnrichedCorr
|
||||
return ordered
|
||||
}
|
||||
|
||||
func cloneTranscript(t *schema.Transcript) *schema.Transcript {
|
||||
if t == nil {
|
||||
return &schema.Transcript{}
|
||||
}
|
||||
|
||||
segments := make([]schema.Segment, len(t.Segments))
|
||||
for i, s := range t.Segments {
|
||||
var categories []string
|
||||
if s.Categories != nil {
|
||||
categories = make([]string, len(s.Categories))
|
||||
copy(categories, s.Categories)
|
||||
}
|
||||
|
||||
segments[i] = schema.Segment{
|
||||
ID: s.ID,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: categories,
|
||||
}
|
||||
}
|
||||
|
||||
return &schema.Transcript{Segments: segments}
|
||||
}
|
||||
|
||||
func newSkippedChange(proposal EnrichedCorrectionProposal, reason ProposalSkipReason) SkippedChange {
|
||||
return SkippedChange{
|
||||
ProposalIndex: proposal.ProposalIndex,
|
||||
|
||||
@@ -198,7 +198,7 @@ func TestApplyProposalsReplaceAllMultipleReplacements(t *testing.T) {
|
||||
|
||||
func TestApplyProposalsNoMutationOfInputTranscript(t *testing.T) {
|
||||
transcript := &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "hello"}}}
|
||||
before := cloneTranscript(transcript)
|
||||
before := transcript.Clone()
|
||||
|
||||
proposals := []EnrichedCorrectionProposal{
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||
return RunOutput{}, fmt.Errorf("runner module factory is required")
|
||||
}
|
||||
|
||||
working := cloneTranscript(input.Transcript)
|
||||
working := input.Transcript.Clone()
|
||||
results := make([]ModuleResult, 0, len(input.ModuleSpecs))
|
||||
sections, err := chunkWorkingTranscript(input.Config, working)
|
||||
if err != nil {
|
||||
@@ -939,25 +939,3 @@ func transcriptFromSection(section chunking.Section) *schema.Transcript {
|
||||
copy(segments, section.Segments)
|
||||
return &schema.Transcript{Segments: segments}
|
||||
}
|
||||
|
||||
func cloneTranscript(t *schema.Transcript) *schema.Transcript {
|
||||
if t == nil {
|
||||
return &schema.Transcript{}
|
||||
}
|
||||
segments := make([]schema.Segment, len(t.Segments))
|
||||
for i, s := range t.Segments {
|
||||
var categories []string
|
||||
if s.Categories != nil {
|
||||
categories = append([]string(nil), s.Categories...)
|
||||
}
|
||||
segments[i] = schema.Segment{
|
||||
ID: s.ID,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: categories,
|
||||
}
|
||||
}
|
||||
return &schema.Transcript{Segments: segments}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user