crosslang

package
v0.1.147 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package crosslang implements cross-language subtitle alignment using anchor-based matching and dynamic programming.

Index

Constants

View Source
const MinCuesForSync = 5

MinCuesForSync is the minimum number of cues required for alignment. Must match subsync.MinCuesForSync — kept as a const here to avoid a circular import between subsync and crosslang.

Variables

This section is empty.

Functions

func CountCognates

func CountCognates(a, b []string) int

CountCognates counts cognate pairs between two word lists.

func CountShared

func CountShared(a, b []string) int

CountShared counts exact string matches between two slices.

func CountSharedFold

func CountSharedFold(a, b []string) int

CountSharedFold counts case-insensitive matches between two slices.

func EditDistance

func EditDistance(a, b string) int

EditDistance computes the Levenshtein distance between two strings.

func IsCognate

func IsCognate(a, b string) bool

IsCognate returns true if two words are likely cognates.

func IsLatinWord

func IsLatinWord(s string) bool

IsLatinWord returns true if the string contains only Latin letters.

func WeightedMedianOffset

func WeightedMedianOffset(pairs []CuePair) int64

WeightedMedianOffset computes the weighted median offset from pairs.

Types

type Anchor

type Anchor struct {
	Punctuation string
	Numbers     []string
	ProperNouns []string
	Cognates    []string
	WordCount   int
	CharLen     int
}

Anchor represents language-independent features extracted from a subtitle cue.

func ExtractAnchors

func ExtractAnchors(text string) Anchor

ExtractAnchors extracts language-independent features from cue text.

type Cue

type Cue struct {
	Text  string
	Start time.Duration
	End   time.Duration
}

Cue represents a single subtitle cue with timing and text. Structurally identical to subsync.Cue to allow zero-copy conversion.

type CuePair

type CuePair struct {
	IncIdx   int
	RefIdx   int
	Score    float64
	OffsetMs int64
}

CuePair holds a matched pair of cues with their similarity score. Exported for test compatibility with the parent subsync package.

func DPAlign

func DPAlign(pairs []CuePair) []CuePair

DPAlign finds the optimal monotonic alignment path.

type Result

type Result struct {
	Cues       []Cue
	Offset     int64   // milliseconds
	Rate       float64 // always 1.0 for crosslang
	Confidence float64
}

Result holds the output of cross-language alignment.

func Align

func Align(ctx context.Context, reference, incorrect []Cue) Result

Align finds the best constant offset between reference and incorrect subtitles using cross-language anchor matching.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL