Documentation
¶
Overview ¶
Package spelling finds one name spelled two ways.
A library's genres, tags, studios and the names in a music collection's tags arrive as people and taggers typed them: "Sci-Fi" and "sci fi", "Amélie" and "Amelie", "Warner Bros." and "Warner Bros. Pictures", "Noir" and "Nior". Key folds the spellings that mean the same thing onto one string, and TypoApart and TruncationOf say when two keys that still differ are a slip of the keyboard or a name cut short rather than two names. Detection is all this does; which spelling to keep is the caller's to decide.
The detectors were found in real libraries first (abs-mcp's and embyfin-mcp's spelling audits), and each rule says what it was for.
Index ¶
- func Distance(a, b string, limit int) int
- func DroppedFromMiddle(short, long string) bool
- func FoldLetter(r rune) string
- func Key(s string) string
- func Letters(s string) int
- func Marks(v string) string
- func SlipsInWords(a, b string) bool
- func Swapped(a, b string) bool
- func TruncationOf(short, long string) bool
- func TypoApart(a, b string) bool
- func WordRune(r rune, afterLatin bool) (spelling string, word bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Distance ¶
Distance is the Damerau-Levenshtein distance (optimal string alignment, so a transposition is one edit), capped: anything past limit comes back as limit+1, and strings whose lengths differ by more than limit are not walked.
func DroppedFromMiddle ¶
DroppedFromMiddle says whether short is long with letters dropped from between its first and its last: "nr" from "noir". A letter added or lost at either end ("age", "rage") makes another word as often as not, and so does one changed ("life", "lift").
func FoldLetter ¶
FoldLetter is the plain-ASCII spelling of an accented Latin letter, or "" for a rune that is not one: é is e, ß is ss, þ is th.
func Key ¶
Key lowercases a value, folds accented letters to plain ones, turns the separators people type interchangeably (_ - . /) into spaces, and drops the rest of the punctuation: "Sci-Fi" and "sci fi" meet at "sci fi". A letter or digit of any other script is kept as it is, lowercased, so "進撃の巨人" and "鬼滅の刃" stay two values rather than both folding to nothing.
func Letters ¶
Letters is how long a value is, in letters rather than bytes: an ideograph takes three bytes, and counted that way a two-letter name passed for a six-letter one and was judged a typo apart from every other two-letter name sharing one of its letters.
func Marks ¶
Marks are the marks in a value that make another name of it, in the order they come: a plus, a bang, a bracket - "discovery+" is a streaming brand and "Discovery" a channel, "Idea(L)" a company and "Ideal" another. Case, spacing, accents, separators, an apostrophe or an ampersand make no other name ("Action & Adventure" is "Action Adventure"), and Key folds them; two values of one Key and different Marks are two names.
func SlipsInWords ¶
SlipsInWords says whether two values of as many words differ only by slips within words: each word that differs is five letters or more and one edit from the other, or a shorter one with two letters swapped ("Nior" for "Noir", "Flim" for "Film") or letters dropped from its middle ("Nr"). A shorter word otherwise an edit or two apart is as often another word as a slip - "teenage life" and "teenage love", "coming of age" and "coming of rage" - and the values two things. Values of more or fewer words differ by a space added or dropped, which is a slip.
func Swapped ¶
Swapped says whether two words are one with two letters next to each other swapped: "nior" and "noir".
func TruncationOf ¶
TruncationOf reports whether short is long cut off ("warner bros" in "warner bros pictures"): at least six letters, and whole words. Both are keys (Key).
func TypoApart ¶
TypoApart reports whether two keys (Key) differ by a slip of the keyboard: one edit for anything six letters or longer, two for twelve or longer when they start with the same word - and, between values of as many words, every word that differs is a slip itself (SlipsInWords).
func WordRune ¶
WordRune is how a fold for comparing names reads a rune past ASCII. An accented Latin letter is its plain spelling (FoldLetter), and any other letter or digit is itself, whatever its script: dropping those made every name written in Japanese, Greek or Cyrillic fold to nothing, so unrelated ones all met. A combining mark belongs to the letter before it: on a plain Latin letter (afterLatin) it is an accent written apart (e and U+0301 for é), folded away as the composed letter's is, and in a script that writes its vowels as marks it is part of the word and kept. word is false for punctuation, symbols and spaces.
Types ¶
This section is empty.