Text nysiis encode - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Text is 0.7.0 — read its documentation.
Home › Text › Phonetic encoding
The NYSIIS code of one name.
public static string Encode(ReadOnlySpan<char> value)
public static string Encode(string value)Parameters — value is a single name. Case does not matter: the name is uppercased by the full
case mapping and read one grapheme cluster at a time. A character no rule names — an apostrophe,
a hyphen, a space — is kept in the code where it stands, as jellyfish keeps it: O'Brien is
O'BRAN. The string overload forwards to the span one.
Returns — string, an uppercase code of variable length, or the empty string when value is
empty.
Exceptions — ArgumentNullException when value is null (the string overload only; a
ReadOnlySpan<char> cannot be null). An empty string is accepted and encodes to the empty string.
Example — two name-specific opening rules, and the b/p distinction Soundex loses.
using Lodestar.Text.Phonetics;
string pf = Nysiis.Encode("Pfister"); // => FASTAR
string sch = Nysiis.Encode("Schmidt"); // => SNAD
string robert = Nysiis.Encode("Robert"); // => RABAD
string rupert = Nysiis.Encode("Rupert"); // => RAPADRemarks — Pfister → FASTAR is NYSIIS reading an initial PF as the f sound it is in a
German-derived surname, which is the kind of rule it carries and the reason it is described as a
name encoder rather than a word encoder.
Robert and Rupert landing on RABAD and RAPAD is the counterpart to
Soundex.Encode giving both R163. Neither is wrong — they are answering
different questions, and which one you want depends on whether a false match or a missed match is
the expensive mistake.
Because the code is not truncated, its length tracks the length of the name. Two names of very different lengths will not collide here even when they start alike, which is most of where the precision comes from.
Applies to — net10.0, netstandard2.0.
See also — Nysiis, Soundex.Encode,
the phonetics index.