names — a deterministic, explaining name normalizer
names reads a place or a person name the way it was typed and says what it is and why. It has one interface,
normalize(text, lang?) → [(candidate, confidence, reason)], a library, a command line and a local socket server.
It makes no external call, keeps nothing of a query and writes no log line about one. No model is called: every
step is a table lookup or a comparison of counts that the reason chain prints.
cargo build --release -p names
names extract --seeds wd.tsv [--seeds more.tsv] [--depth 8] [--dir STORE] --out places.jsonl
names build --records places.jsonl --list weather=wd.tsv [--list locations=wd2.tsv] [--gali DIR] --out names.idx
names query --index names.idx [--lang uk] [--only BITS] [--top N] [--json] [TEXT ...] # stdin lines without TEXT
names person --index names.idx TEXT ... # the person key and blocking key
names compare --index names.idx A B # same / compatible / different, with reasons
names serve --index names.idx --socket PATH # Unix socket, mode 0600
names client --socket PATH [--quiet] < requests # send request lines, print answers, time to stderr
names tables [--index names.idx] # the letter table and the key merges with PanPhon distances
names bench-places --records places.jsonl --list ... --out DIR [--seed S]
names bench-names --index names.idx --out DIR [--n 2000] [--seed S]
A library user who only loads an index and asks takes the crate without its default build feature: the
dependencies are then unicode-normalization and anyhow.
Sources
- Places: Mova's Wikidata store, read entity by entity through
tools/wikidata-store(the store is never read whole).extracttakes qid lists (wd.tsv: the Falcon's and the locations' lists) and followsP131(located in) andP17(country) upward, so the regions and countries of agent strings are in the index too. Each record keeps the labels and aliases in every language, the titles of the sitelinks to language Wikipedias,P31,P17,P131, the population (P1082: best rank, latest point in time), the coordinates (P625), the sitelink count and the ISO codes (P297,P298,P300). Wikidata is CC0 1.0. - The K1 letter tables: gali-inner's
transliteration/en.words(words of English Wikipedia in a non-Latin script with their CLDR Any-Latin transliteration), aligned letter by letter bynoisy::translit::align; Cyrillic spellings go through noisy's chat/passport digraph rule. Cyrillic, Greek, Armenian and Georgian get a table; a second Cyrillic table without marks (ч → c) serves the person readings. - The keyboard layouts: noisy's xkb pairs of each native layout with English (
noisy::keyboard), for the alphabets (Cyrillic, Greek, Armenian, Georgian); stored in the index.
The keys
| key | function | collapses |
|---|---|---|
K0 fold | lowercase, NFKD, combining marks off (й ў keep theirs), ł ø đ ß æ œ ı by table, ё → е, apostrophes out, other non-letters → one space | case, Latin diacritics, compatibility forms, punctuation |
K1 latin | non-Latin letters through the script table, marked Latin letters by the digraph convention (č → ch, š → sh, ž → zh, ś → sh), then K0 | the script |
K2 roman | K1 without spaces read as classes: S (s ss sh sch sz shch szcz), Z (z zh dz dzh dj), X (kh ch h cz tsch tch), C (ts tz, c before e i y), K (k c q ck), F (f ph), V (v w), T (t th); ae oe ue → a o u; y i j one class, dropped inside a run with another vowel; doubled classes once | romanization conventions, iotation, spacing |
K3 skel | K2 with every vowel run one slot, S Z C one class, G with X | vowel quality, sibilant voicing, g/h |
K2 is a function of K1 and K3 of K2; K0 is a separate branch (it folds š to s where K1 spells sh), so the matcher
reads all four. names tables prints the PanPhon distance of the sounds inside each merged class: the K2 classes S
and Z join sounds one or two features apart, X joins x, h and tʃ (a convention of spelling, not of sound: Polish
and German ch is x, English ch is tʃ).
names build reports, per level, the keys that name more than one place and the mean number of places per key:
the collisions each key adds.
Places
- kept: an e-mail, a URL, a number or date, or a code (letters with digits) comes back unchanged;
- coordinates:
50°27′N 30°31′E,50.45N 30.52E,50.45, 30.52→ a coordinate candidate and the nearest listed places; - agent string: the whole text is tried first; with commas or parentheses the first part is the place and the
rest are hints, each an ISO code (
UA,USA,NYas the tail ofUS-NY) or a region or country name; a candidate outside a hinted region keeps 5 % of its weight; - lookup: K0–K3 of the place part; when nothing meets at K0 or K1: the readings through the keyboard layouts
(
uk-on-en: rbtd → киев; fold key only), the core without the generic words of place names (city,of,district,munisipyo,район: words in the forms of at least 100 places that stand alone in at most 2 % of them), and with no direct hit the one-edit neighbours of a K3 key of six symbols or more; - score: share = w·λ(level) / Σ w·λ, with w the population (else 1000 per sitelink), an administrative ancestor ×0.01, a layout reading ×0.5, a core hit ×0.3, and λ = 1, 0.5, 0.01, 0.001 for K0–K3 (λ and the ancestor factor tuned on the tune half); confidence = Q(level, key length) × share, with Q calibrated on the tune half: the chance that a top match of that level and key length is right, from the held-out aliases against the control strings (prior ½). Candidates are ordered by confidence.
Every candidate carries its reasons, for instance Kijów: pl label of Q1899; diacritic ó→o; level fold, key length 5 (quality 0.76); share 0.963 of weight × likelihood among 9 candidates (population 2952301).
Persons
A form is cut into tokens; one letter, or two with a dot, is an initial. person gives key (the K2 of the full
tokens in order, then the initials: token order never matters) and block (their K3, for blocking). compare
pairs full tokens at K0, K1, K2 of any reading, or K3, and initials by their first sound; besides its K2 a token has
readings: Cyrillic no-marks (ч → c: a name romanized and stripped of its diacritics) and uk-h (г as h); Latin
french (ch → sh, j → zh, ou → u), polish-czech (c → ts), german (z → ts, s → z, sh → zh). The verdict is
different when no full token pairs or both sides keep an unpaired token, same when every pair meets at K2 or
stronger, compatible for a K3-only pair, an initial that agrees only by a first letter, or two forms in one
non-Latin script that differ in letters. A language reading caps the confidence at 0.85.
Measurements
bench-places holds out one alias of each listed place (removed from the index, queried in its language; hard:
no case or mark variant of it is left), plants noise in the English label of each place of the first list (one edit
by each of noisy's visual, phonetic and translit models; the layout models over the whole text), and queries the
controls: seeded random strings, common English words, Ukrainian headwords, and generated codes, e-mails and
numbers, which must come back unchanged. It tunes λ and the ancestor factor and fits Q on the tune half (an even
seeded hash) and reads the test half. summary.json holds top-1, top-3, the share of confident answers (≥ 0.5) and
their precision, the level each place was found at, and the latency.
Persons (bench-names): synthetic Ukrainian-like names (seeded syllables, no list of real names) in Cyrillic against seven
romanization styles of hand tables of the bench (passport 2010, Russian-like, German, Polish, French, ISO 9, ISO 9
without marks) and five layouts; controls: one letter of the surname changed, another given name or initial, an
unrelated name.
Limits
- The place index covers the listed places and their ancestors, not every settlement of Wikidata; a query for a place outside the lists finds nothing or a namesake.
- An alias in a script without a table (Arabic, Hebrew, Devanagari, Han …) matches only at K0, in its own script.
- Homonyms are told apart by weight and hints alone: a bare
Springfieldgets the largest one with a low share. - The persons' K2 cannot tell apart names that differ only in і/и or у/ю (the same letters once transliterated):
across scripts they come out
same; the French, German and Polish readings also join с/з and ш/ж. - Initials of digraph letters (Х., Ж., Ш.) meet
K.,J.,S.only ascompatible. - The keyboard readings are the 59 xkb layouts' alphabets with English; Korean (an automaton) and the syllabic and consonantal scripts are left out; a reading counts only at K0.
- The quality table and λ are fitted on one set of held-out aliases and controls; they are rules of this crate, not universal constants.
This page in Markdown https://md.mova.elamur.ai/free/en/docs/tools/names/