Keep transcript decoding and encoding on typed data
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package normalization
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -292,25 +293,7 @@ func TestNormalizationGoldenBareArrayTranscript(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/bare_array_transcript.golden.json")
|
||||
@@ -318,12 +301,12 @@ func TestNormalizationGoldenBareArrayTranscript(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenObjectWithSegmentsTranscript(t *testing.T) {
|
||||
@@ -345,25 +328,7 @@ func TestNormalizationGoldenObjectWithSegmentsTranscript(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/object_with_segments_transcript.golden.json")
|
||||
@@ -371,12 +336,12 @@ func TestNormalizationGoldenObjectWithSegmentsTranscript(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenTranscriptWithCategories(t *testing.T) {
|
||||
@@ -398,25 +363,7 @@ func TestNormalizationGoldenTranscriptWithCategories(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/transcript_with_categories.golden.json")
|
||||
@@ -424,12 +371,12 @@ func TestNormalizationGoldenTranscriptWithCategories(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenTranscriptWithOriginalIDs(t *testing.T) {
|
||||
@@ -451,25 +398,7 @@ func TestNormalizationGoldenTranscriptWithOriginalIDs(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/transcript_with_original_ids.golden.json")
|
||||
@@ -477,12 +406,12 @@ func TestNormalizationGoldenTranscriptWithOriginalIDs(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenSameSpeakerMerge(t *testing.T) {
|
||||
@@ -504,25 +433,7 @@ func TestNormalizationGoldenSameSpeakerMerge(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/transcript_same_speaker_merge.golden.json")
|
||||
@@ -530,12 +441,12 @@ func TestNormalizationGoldenSameSpeakerMerge(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenEllipsisMerge(t *testing.T) {
|
||||
@@ -557,25 +468,7 @@ func TestNormalizationGoldenEllipsisMerge(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/transcript_ellipsis_merge.golden.json")
|
||||
@@ -583,12 +476,12 @@ func TestNormalizationGoldenEllipsisMerge(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func TestNormalizationGoldenDifferentSpeakersNoMerge(t *testing.T) {
|
||||
@@ -610,25 +503,7 @@ func TestNormalizationGoldenDifferentSpeakersNoMerge(t *testing.T) {
|
||||
t.Fatalf("failed to parse source transcript: %v", err)
|
||||
}
|
||||
|
||||
converted := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
converted.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
normalized, _ := normalizer.Normalize(converted)
|
||||
normalized, _ := normalizer.Normalize(transcript.Canonical())
|
||||
|
||||
// Compare with golden output semantically
|
||||
expectedRaw, err := os.ReadFile("testdata/transcript_different_speakers_no_merge.golden.json")
|
||||
@@ -636,12 +511,12 @@ func TestNormalizationGoldenDifferentSpeakersNoMerge(t *testing.T) {
|
||||
t.Fatalf("failed to read golden fixture: %v", err)
|
||||
}
|
||||
|
||||
expectedTranscript, err := schema.ParseTranscriptJSON(expectedRaw)
|
||||
if err != nil {
|
||||
var expectedTranscript schema.Transcript
|
||||
if err := json.Unmarshal(expectedRaw, &expectedTranscript.Segments); err != nil {
|
||||
t.Fatalf("failed to parse golden transcript: %v", err)
|
||||
}
|
||||
|
||||
assertTranscriptsEqual(t, normalized, expectedTranscript)
|
||||
assertTranscriptsEqual(t, normalized, &expectedTranscript)
|
||||
}
|
||||
|
||||
func assertTranscriptsEqual(t *testing.T, actual, expected *schema.Transcript) {
|
||||
|
||||
Reference in New Issue
Block a user