Text matchratingapproach codex - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.6.0 — read its documentation.

HomeTextPhonetic encoding

MatchRatingApproach.Codex

The Match Rating codex of one name.

public static string Codex(string value)
public static string Codex(ReadOnlySpan<char> value)

Parametersvalue is a single name: any Unicode letter plus a single space is accepted; a digit, punctuation or any other whitespace is refused rather than ignored. Case does not matter. The string overload forwards to the span one.

Returnsstring, an uppercase code of 1 to 6 characters, or the empty string when value is empty.

ExceptionsArgumentNullException when value is null (the string overload only). ArgumentException when value holds a character that is neither a letter nor a space.

Example — doubles collapse before non-leading vowels are dropped, and a code over six characters keeps only its first three and last three.

using Lodestar.Text.Phonetics;

string smith = MatchRatingApproach.Codex("Smith");             // => SMTH
string mississippi = MatchRatingApproach.Codex("Mississippi"); // => MSSP
string bhattacharya = MatchRatingApproach.Codex("Bhattacharya");   // => BHTHRY

RemarksMississippi reducing to MSSP is doubled letters collapsing before the non-leading vowels between them are dropped: the raw sequence M-I-S-S-I-S-S-I-P-P-I collapses its adjacent-letter runs first (M-I-S-I-S-I-P-I), and only then loses every vowel but the first character, whatever it is — a leading vowel is kept, as in Codex("aeiou")"A".

Bhattacharya reducing to six characters (BHTCHRY would be seven) keeps its first three and its last three: BHT + HRY. A name that already fits in six is never touched, however it was spelled.

A character that is neither a letter nor a space throws instead of being dropped — Codex("O'Brien") and Codex("Anne-Marie") both raise ArgumentException, naming the character that stopped them. Soundex.Encode, Metaphone.Encode and Nysiis.Encode ignore the same input instead — a deliberate difference, recorded in the phonetics index and the equivalence table.

Applies to — net10.0, netstandard2.0.

See alsoMatchRatingApproach, MatchRatingApproach.Compare, the phonetics index.

⚠️ **GitHub.com Fallback** ⚠️