spelling

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: GPL-3.0 Imports: 3 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(a, b string, limit int) int

Distance is the edit distance with a swap counting as one edit, capped: anything past limit comes back as limit+1.

func DroppedFromMiddle

func DroppedFromMiddle(short, long string) bool

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

func FoldLetter(r rune) string

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

func InitialsOf(short, long string) bool

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

func Key(s string) string

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

func Letters(s string) int

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

func Marks(v string) string

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

func SlipsInWords(a, b string) bool

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

func Swapped(a, b string) bool

Swapped says whether two words are one with two letters next to each other swapped: "nior" and "noir".

func TruncationOf

func TruncationOf(short, long string) bool

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

func TypoApart(a, b string) bool

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

func WordRune(r rune, afterLatin bool) (spelling string, word bool)

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.

Jump to

Keyboard shortcuts

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