Skip to content

stoa-predict: choose prediction languages in Stoa Settings, frequency-ranked suggestions - #210

Merged
VictorGSchneider merged 1 commit into
mainfrom
claude/tender-dirac-0bc2zn
Oct 22, 2026
Merged

VictorGSchneider merged 1 commit into
mainfrom
claude/tender-dirac-0bc2zn

Conversation

@VictorGSchneider

Copy link
Copy Markdown
Owner

What

Super+S → Keyboard → Text prediction is a new submenu with:

  • Prediction (on/off): the same toggle as Super+Shift+S.
  • Languages: a checklist of 21 languages (English, Português (Brasil/Portugal), Español, Français, Deutsch, Italiano, Nederlands, Català, Română, Polski, Čeština, Svenska, Dansk, Norsk, Suomi, Magyar, Türkçe, Ελληνικά, Русский, Українська). Each one shows whether its word list is already downloaded.

When you save, stoa-predict set-languages downloads any missing list into ~/.local/share/stoa/predict/ and writes the choice to ~/.config/stoa/predict-languages. It then restarts prediction if it is on. If a download fails, nothing is saved and the previous choice keeps working.

Word lists

FrequencyWords gives the 50k most common words per language with their counts (OpenSubtitles 2018, CC BY-SA 4.0, ~600 KB each). The lists are downloaded on demand rather than vendored, and the README credits the source.

aspell was considered and rejected: aspell -d pt_BR dump | expand produces about 10.5M forms with no usage ranking, and Latin-1 output by default.

Engine (WordDictionary in stoa-predict.py)

  • Ranking: suggestions are ranked by frequency instead of alphabetically. wh → what, who, why, when, where; obr → obrigado, obrigada, obra.
  • Several languages: they are merged by relative frequency within each language.
  • Accents: lookup ignores accents, so nao → não and acao → ação.
  • Noise filtering:
    • A spelling is dropped when it is under 5% as frequent as the commonest word that folds the same way (nâo/näo next to não). Real pairs such as esta/está survive.
    • Words with U+0080–U+00BF are dropped; in these lists that is always UTF-8 read as Latin-1 (vocãª).
  • Custom words: ~/.config/stoa/predict-words.txt still works, and those words rank first.
  • Fallback: /usr/share/dict/words is used when no language list is downloaded.
  • Install default: a fresh install.sh starts with pt_br en; offline it skips this quietly.

Verification

  • Engine against the real lists:
    • en: th → the, that, this, there, they.
    • pt_br: voc → você, vocês; est → está, estou, estava.
    • en + pt_br: co → com, como, come, coisa, could.
    • Lookups take ~1 ms per keystroke; loading takes 0.7 s for two languages.
  • Controller: languages lists the catalog; set-languages pt_br en downloads and saves; an unknown code exits 2 and leaves the previous choice intact.
  • Settings dialog: run in headless sway against the real controller. Ticking Español with the keyboard downloaded es.txt, saved en pt_br es and showed the success notification.
  • Bugs this test caught:
    • GTK rejected the non-ASCII language names without a UTF-8 locale, so the dialog now runs under C.UTF-8 when needed.
    • A failed restart of a running prediction was reported as "could not save", although the save had happened. It is now a warning.
  • Input method: in a GTK field, obr → ↓ Enter gave obrigado , nao gave não , and graci gave gracias (from Español).
  • Repo checks: tests/run.sh 18 passed; ruff and config-integrity are clean; shellcheck shows no new findings.

Generated by Claude Code

Super+S → Keyboard → Text prediction now turns prediction on/off and
opens a checklist of 21 languages. Ticked languages are downloaded on
demand (FrequencyWords, OpenSubtitles 2018, CC BY-SA 4.0, ~600 KB each)
into ~/.local/share/stoa/predict and listed in
~/.config/stoa/predict-languages; prediction restarts to use them.

The word engine changes with it: suggestions are ranked by how often a
word is used ("wh" → what, who, why…; "obr" → obrigado, obra…) instead
of alphabetically, languages are merged by relative frequency, and the
lookup ignores accents ("nao" → não). Accent-only typos that are rare
next to the common spelling and UTF-8-as-Latin-1 noise in the lists are
dropped. The system word list stays as the fallback.

install.sh starts a fresh install with pt_br + en. The checklist runs
yad under C.UTF-8 when the session locale is not UTF-8: GTK otherwise
rejects the language names in argv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CrdbH4MCHhLKimzdRSzXZp
@VictorGSchneider VictorGSchneider self-assigned this Oct 22, 2026
@VictorGSchneider
VictorGSchneider merged commit fabee37 into main Oct 22, 2026
3 checks passed
@VictorGSchneider
VictorGSchneider deleted the claude/tender-dirac-0bc2zn branch October 22, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants