func Encode
Encode returns the four-character Soundex key for s, or "" when s contains no ASCII letters. Non-letters are ignored, so "O'Brien" and "OBrien" agree.
Package soundex implements the Soundex phonetic algorithm as a pure, reusable package: names that sound alike in Engl...
gno.land/p/moul/x/daily/soundex/v0Soundex phonetic algorithm — Encode, Match, EncodeAll, Normalize.
Names that sound alike in English encode to the same four-character key:
Robert and Rupert both give R163.
1import "gno.land/p/moul/x/daily/soundex/v0"
2
3soundex.Encode("Robert") // "R163"
4soundex.Encode("Ashcraft") // "A261"
5soundex.Match("Robert", "Rupert") // true
The 1918 Russell/Odell algorithm as used by the US census, with the three rules that are usually got wrong implemented explicitly — each has a test:
Pfister → P236, not P123;h and w are transparent: consonants either side are treated as
adjacent, so Ashcraft → A261, not A226;Tymczak → T522.Non-letters are ignored, so O'Brien and OBrien agree. Input with no ASCII
letters has no key (""), and Match never reports two such inputs as
matching — "no name" is not a name they share.
Soundex is English-centric and lossy by design: it is a blocking key for finding candidates cheaply, never proof that two names are the same.
Live demo: r/moul/x/daily/soundexdemo
· render it at /r/moul/x/daily/soundexdemo/v0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.
Package soundex implements the Soundex phonetic algorithm as a pure, reusable package: names that sound alike in English encode to the same four-character key, so "Robert" and "Rupert" both give R163.
This is the 1918 Russell/Odell algorithm as used by the US census, with the rules that are usually got wrong implemented explicitly:
Soundex is English-centric and lossy by design: it is a *blocking* key for finding candidates, never a proof that two names match.
A live demo of this package is at r/moul/x/daily/soundexdemo(/r/moul/x/daily/soundexdemo/v0).
Encode returns the four-character Soundex key for s, or "" when s contains no ASCII letters. Non-letters are ignored, so "O'Brien" and "OBrien" agree.
EncodeAll returns the keys for each input, in order.
Match reports whether two strings share a Soundex key. Empty keys never match, so two inputs with no letters are not "the same name".
Normalize upper-cases and strips non-letters — the input Encode actually sees. Exposed so callers can show their work.