Documentation
¶
Overview ¶
Package spelling finds one name spelled two ways, as genres, tags and studios arrive typed by hand: "Sci-Fi" and "sci fi", "Amélie" and "Amelie", "Noir" and "Nior". Key folds spellings that mean the same onto one string; TypoApart, TruncationOf and InitialsOf say when two keys that still differ are a slip, a name cut short or an initial. Which spelling to keep is the caller's to decide. Each rule says what real library it was found in.
Index ¶
- func Distance(a, b string, limit int) int
- func DroppedFromMiddle(short, long string) bool
- func FoldLetter(r rune) string
- func InitialsOf(short, long string) bool
- 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 edit distance with a swap counting as one edit, capped: anything past limit comes back as limit+1.
func DroppedFromMiddle ¶
DroppedFromMiddle says whether short is long with letters dropped from between its first and last: "nr" from "noir". A letter lost at an end ("age", "rage") makes another word as often as not.
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 InitialsOf ¶ added in v0.5.0
InitialsOf reports whether two keys are one person's name, one with the first name reduced to its initial: "c z dunn" is "christian dunn". The last name must match and be three letters or more, and the initial one letter: "joe hill" and "joey w hill" are two people.
func Key ¶
Key lowercases, folds accents to plain letters, turns _ - . / into spaces and drops the rest of the punctuation: "Sci-Fi" and "sci fi" meet at "sci fi". Letters of other scripts are kept, so two Japanese titles stay two values.
func Letters ¶
Letters is a value's length in letters, not bytes: counted in bytes a two-ideograph name passed for a six-letter one.
func Marks ¶
Marks are the marks in a value that make another name of it, in order: "discovery+" is a brand and "Discovery" a channel. Case, spacing, accents and separators make no other name and Key folds them; two values of one Key and different Marks are two names.
func SlipsInWords ¶
SlipsInWords says whether two values differ only by slips within words: a word of five letters or more one edit away, or a shorter one with two letters swapped ("Nior") or dropped from its middle ("Nr"). A short word otherwise an edit apart is as often another word: "teenage life" and "teenage love". A different word count is a space 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 differ by a slip: one edit at six letters or more, two at twelve when they start with the same word, and every differing word a slip itself (SlipsInWords).
func WordRune ¶
WordRune is how a name fold reads a rune past ASCII: an accented Latin letter as its plain spelling (FoldLetter), any other letter or digit as itself. A combining mark after a plain Latin letter (afterLatin) is an accent written apart and folds away; in a script that writes vowels as marks it is kept. word is false for punctuation, symbols and spaces.
Types ¶
This section is empty.