Minor updates to overlap detection and segment coalescing logic
This commit is contained in:
@@ -3,6 +3,7 @@ package filler
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
||||
)
|
||||
@@ -15,10 +16,10 @@ var patterns = []*regexp.Regexp{
|
||||
}
|
||||
|
||||
// Apply tags short filler segments.
|
||||
func Apply(in model.MergedTranscript) (model.MergedTranscript, int) {
|
||||
func Apply(in model.MergedTranscript, maxDuration float64) (model.MergedTranscript, int) {
|
||||
tagged := 0
|
||||
for index := range in.Segments {
|
||||
if !matches(in.Segments[index]) || hasCategory(in.Segments[index], Category) {
|
||||
if !matches(in.Segments[index], maxDuration) || hasCategory(in.Segments[index], Category) {
|
||||
continue
|
||||
}
|
||||
in.Segments[index].Categories = append(in.Segments[index].Categories, Category)
|
||||
@@ -27,15 +28,15 @@ func Apply(in model.MergedTranscript) (model.MergedTranscript, int) {
|
||||
return in, tagged
|
||||
}
|
||||
|
||||
func matches(segment model.Segment) bool {
|
||||
text := strings.TrimSpace(segment.Text)
|
||||
func matches(segment model.Segment, maxDuration float64) bool {
|
||||
text := normalizeForMatching(segment.Text)
|
||||
if text == "" {
|
||||
return false
|
||||
}
|
||||
if len(strings.Fields(text)) > 3 {
|
||||
return false
|
||||
}
|
||||
if segment.End-segment.Start > 1.0 {
|
||||
if segment.End-segment.Start > maxDuration {
|
||||
return false
|
||||
}
|
||||
for _, pattern := range patterns {
|
||||
@@ -46,6 +47,16 @@ func matches(segment model.Segment) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func normalizeForMatching(text string) string {
|
||||
text = strings.Map(func(r rune) rune {
|
||||
if unicode.IsPunct(r) {
|
||||
return ' '
|
||||
}
|
||||
return r
|
||||
}, text)
|
||||
return strings.Join(strings.Fields(text), " ")
|
||||
}
|
||||
|
||||
func hasCategory(segment model.Segment, category string) bool {
|
||||
for _, existing := range segment.Categories {
|
||||
if existing == category {
|
||||
|
||||
Reference in New Issue
Block a user