Expand description
Whether a complete word was typed in the wrong layout, and what it should read instead.
infer compares two readings of one key sequence: the word as typed, in the language of the
active input mode (the source), and the same keys read in the other layout (the candidate). A
false change rewrites a word the user typed correctly, and that costs far more than a missed
correction, so abstention is the default. Each step in the table either ends the decision or
passes it on, and all but two of them can only abstain.
step, in order result
------------------------------------------------------------- ------------------------
manual or reversal intent at this boundary 7 ExplicitIntent
no mode, over 32 units, no letters or letters outside the
mode's script, invalid policy, mixed case or a multi-letter
capital word 1 Ineligible
the English or the Russian Vim source is missing 6 DictionariesMissing
word or core recognized or rare in a vocabulary source 2 Personal
core in the source lexicon and not yielding 3 Known
candidate not all in the target script 1 Ineligible
candidate forbidden in a vocabulary source 4 Forbidden
candidate not in the target lexicon, or below minimum Zipf 5 Weak
core in the source lexicon and yielding 0 Correction, Zipf margin
score below log10(cost) + length penalty 5 Weak, with the score
otherwise 0 Correction, with the scoreFrequencies are compared on the Zipf scale, log10 of occurrences per billion words, which is the stored log10 frequency plus 9. The score of the last two steps is a log10 odds:
score = log10 f(candidate) - log10 P(letters) + provisional penalties
+ log10(prior / (1 - prior)) + log10(context factor)Here f is the candidate’s corpus frequency in the target lexicon and P the source
language’s character chain over the typed letters. The context factor is 19 when the
session’s recent words are in the target language, 1/19 when they are in the source language
and 1 without context. The score must reach log10 of the false-correction cost, plus 4, 2 or
1 for a word of one, two or three units. The prior, the cost and the penalties are ranking
parameters, not calibrated probabilities; the policy is evaluated on pinned corpora
(docs/engine.md).
A typed string that is itself a word of the source lexicon is protected by that alone, and
the chain is never consulted for it. It yields only when it is rare (Zipf below
Policy::known_ceiling) and the candidate is more frequent by a wide margin; the decision
then rests on that frequency ratio, and the margin is its score. A word of one unit never
yields.
In English mode the keys [ ] ; ' , . and the ё key type punctuation, but in Russian they
type letters, so they are provisional: they can start or continue a word (see
is_provisional). For such a word the candidate is the whole key sequence read in Russian,
and the source reading is the letters alone, with a penalty per provisional unit for how
rarely English words carry that punctuation in that position. The core is the word up to its
last letter. Only when every provisional unit trails, as in it., is the core all letters,
and only then can lexicon protection apply.
A three-unit provisional word whose candidate has Zipf at least 4 gets another 3 log10 units
of evidence per leading provisional unit, unless context supports the source language.
Structs§
- Decision
- A correction proposal; never grants native write authority.
- Dictionaries
- Ready protection sources.
Nonemeans missing; an explicitly empty vocabulary is ready. - Policy
- Reference scoring parameters. These are ranking hypotheses, not calibrated probabilities. Zipf values are log10 occurrences per billion words.
- Request
- One word to decide. The caller establishes that the word is complete and owned;
inferstill checks its length, script and case.
Enums§
- Reason
- Decision reasons, numbered as in the reference vectors and the probe output.
Functions§
- detect_
context - Language of the last two words in
prefix, the session’s own finished text. - infer
- Decide one word under
policy, following the steps in the module docs. The result is a proposal only: the caller still controls every native effect. - is_
provisional - Whether
unitis typed in English mode by a key that types a Russian letter:[ ] ; ' , ., the ё key ofkeyboardand their shifted forms. In English mode such a unit can start or continue a word, which keeps its typed form unless the whole word reads as Russian.