DEV Community

Alex Day
Alex Day

Posted on

Rebuilding Sofle-choc on android

I built a custom Android keyboard. It got weird.

A full IME - written in Kotlin, handling every keypress, suggestion, and cursor movement myself. The idea was to replicate the Sofle Choc split. Because.

Here's what actually surprised me building it:

Backspace into a committed word is a whole thing.

Once a word is committed, the suggestion engine loses track of it. Backspacing into it looks like a new character to the IME. Getting autocomplete to pick up the fragment again meant wrapping three API calls in beginBatchEdit/endBatchEdit to stop the editor firing callbacks mid-operation. AnySoftKeyboard does the same thing. Took me way too long to figure out why.

Next-word prediction is more interesting than I expected:

After every committed word, surface what probably comes next - T9 style, but without the hardware. Two layers: a static English seed (Norvig's bigram corpus, MIT licensed) and a personal layer that learns from your actual typing. The scoring uses temporal decay from librime - recent use contributes a near-full boost, something you typed 1000 commits ago contributes almost nothing. Old habits fade. New ones take over within a few hundred keystrokes.

Learned about bigrams, infigrams, suffix-array with binary search and a new shit called #beam_search from github.com/rime/librime

Mixed language (Banglish, Hinglish) works without any language detection, kinda - the personal layer is just a string map. It doesn't care what language you're in. Again, ASK showed the way for MVP.

The suggestion interface mirrors librime's Grammar pattern, context passes through the function call, not stored as shared mutable state. Took one refactor to get there but it cleaned up everything downstream.

A seven part series on the same:
https://ikouchiha47.github.io/keyboard/

Top comments (0)