Metaphone

object Metaphone

A compact Metaphone-class phonetic coder used by the combination/cross-reference search to derive sound-alike container matches GENERICALLY from CMS building names — with NO maintained abbreviation dictionary.

The combination matcher's LOAD-BEARING tier is phonetic-PREFIX, not phonetic-equality: a query token matches a name-word when encode of the token is a PREFIX of encode of the name-word. This is the only derivation that can reach biz/bizz -> business, because:

encode("biz") == encode("bizz") == encode("busi") == "BS" encode("business") == "BSNS" (and "BS" is a prefix of "BSNS")

Soundex-equality fails this case (Soundex("biz")=B200 != Soundex("business")=B252) and Metaphone-EQUALITY fails it too (the codes differ in length), so neither would surface biz. The first-consonant anchor that Metaphone preserves keeps "BS" from prefixing Medical(MTKL...)/Humanities(HMNTS)/Engineering(ENJNR...), which bounds false positives; the matcher additionally requires a real contained entity (intersection guard) before surfacing a building.

This is a deliberately small Metaphone variant covering the transformations the SDK's CMS names exercise; it is deterministic, allocation-light, and case/diacritic handling is done by the caller (tokens arrive already lowercased and diacritic-stripped). Only ASCII letters contribute to a code; everything else (digits, punctuation) yields an empty code, so numeric tokens never phonetically prefix anything.

Functions

Link copied to clipboard

Returns the phonetic code for word (uppercase Metaphone-class symbols), or "" if the word contains no alphabetic characters.

Link copied to clipboard

Convenience: encodes both inputs and reports whether the encoded query token is a phonetic PREFIX of the encoded name word. Inputs are lowercased defensively; diacritics are expected to be stripped by the caller (the matcher's tokenizer does NFKD folding).

Link copied to clipboard
fun isPrefixCode(queryCode: String, nameWordCode: String): Boolean

True when queryCode is a non-empty PREFIX of nameWordCode. This is the phonetic-PREFIX relation the container tier uses (NOT equality). An empty queryCode (e.g. a numeric token) never matches, so numbers can never act as a phonetic container.