Documentation
¶
Index ¶
- func DiffMatchPatch(refText string, asrText string) []diffmatchpatch.Diff
- func DiffPrettyHtml(diffs []diffmatchpatch.Diff) string
- func ErrorCount(diffs []CDiff) int
- func IsHyphen(ch rune) bool
- func IsLikeApostrophe(ch rune) bool
- func IsMatch(diffs []diffmatchpatch.Diff) bool
- func ReadableDiff(diffs []Diff) string
- type CDiff
- type Counts
- type Diff
- type Operation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffMatchPatch ¶
func DiffMatchPatch(refText string, asrText string) []diffmatchpatch.Diff
func DiffPrettyHtml ¶
func DiffPrettyHtml(diffs []diffmatchpatch.Diff) string
func ErrorCount ¶
func IsLikeApostrophe ¶
func IsMatch ¶
func IsMatch(diffs []diffmatchpatch.Diff) bool
func ReadableDiff ¶
Types ¶
type CDiff ¶
func CharLevenshtein ¶
CharLevenshtein aligns refText (reference) against asrText (hypothesis) at the character (rune) level using a classic Levenshtein dynamic-programming alignment where substitution, insertion and deletion each cost 1.
Unlike the diff-match-patch path, substitution is a first-class operation, so a changed character comes back as a single OpReplace (Char=ref rune, Replace=asr rune) rather than a delete+insert pair — and because it works on atomic runes it never splits a multibyte rune or exploits incidental shared characters between unrelated words.
The result is a minimal-cost alignment; when several are minimal, ties are broken in a fixed order (match/substitute, then delete, then insert), which left-aligns edits consistently.
func Diff2CDiff ¶
type Counts ¶
type Counts struct {
Hits int // equal
Substitutions int // replace
Deletions int // delete (in reference, not in hypothesis)
Insertions int // insert (in hypothesis, not in reference)
RefLen int // reference tokens = Hits + Substitutions + Deletions
}
Counts holds the S/D/I/hits breakdown of an alignment.
func CountWords ¶
CountWords tallies a word-level []Diff into S/D/I/hits. Use the resulting Counts.ErrorRate() to get WER: (S+D+I)/RefLen.
func (*Counts) ErrorCount ¶
type Diff ¶
func Convert2Diff ¶
func Convert2Diff(diffs []diffmatchpatch.Diff) []Diff
func DiffConvert ¶
DiffConvert converts diffmatchpathch tree to a diff.Diff tree without modifying it.
func DiffReplace ¶
func WordLevenshtein ¶
WordLevenshtein aligns refText (reference) against asrText (hypothesis) at the WORD level using Levenshtein DP where substitution, insertion and deletion each cost 1. This is the standard basis for Word Error Rate (WER).
Words are split with strings.Fields, so leading/trailing whitespace is ignored and runs of whitespace collapse; the alignment is over words only, so exact spacing is not reconstructable from the result (use the character path when you need that). Normalize (lowercase, strip punctuation, etc.) BEFORE calling if you want those handled — this compares whole words verbatim.
It emits []Diff, matching the DiffReplace/CharDiff convention: Text holds the reference word for Equal/Replace/Delete and the ASR word for Insert; Replace holds the ASR word on a Replace.