T9 Keyboard Emulator Page
def cycle_predictions(self): if self.current_input in self.word_dict: words = self.word_dict[self.current_input] words.append(words.pop(0)) # Rotate return words[0] return None t9 = T9Emulator() t9.load_dictionary(['good', 'home', 'gone', 'hello', 'world', 'test']) print(t9.input_digit('4')) # Possible words starting with G/H/I print(t9.input_digit('6')) # '46' sequence print(t9.input_digit('6')) # '466' sequence print(t9.input_digit('3')) # '4663' -> ['good', 'home', 'gone']
# Example word dictionary t9_dict = '4663': ['good', 'home', 'gone'], '2273': ['case', 'care', 'base'], '96753': ['words', 'world'], '43556': ['hello'], '843': ['the', 'tie', 'vid'] t9 keyboard emulator
pressKey(key)
// Usage const t9 = new T9Emulator(); t9.loadDictionary(['hello', 'good', 'home', 'test', 'world']); console.log(t9.pressKey('4')); // ['good', 'home'] for '4'? Actually '4' = ghi console.log(t9.pressKey('6')); // ['home'] for '46'? Wait, '46' = 'hm'? Let's fix... Here's a starter dictionary with common words: def cycle_predictions(self): if self
loadDictionary(words) words.forEach(word => const seq = this.wordToSequence(word); if (!this.dictionary[seq]) this.dictionary[seq] = []; this.dictionary[seq].push(word); ); Let's fix
Store common words mapped to their T9 sequences:
const starterDictionary = '2': ['a', 'b', 'c'], '22': ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'], '23': ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'], '4663': ['good', 'home', 'gone', 'hood'], '43556': ['hello'], '96753': ['world', 'words'], '843': ['the', 'tie', 'vid'], '2865': ['bunk', 'cunt', 'auto'], '5464': ['king', 'link', 'jink'], '7364': ['send', 'rend', 'pend'] ; 1. Next Word Prediction Allow cycling through predictions with a "Next" key (usually * ) 2. Add Word to Dictionary Let users add new words that aren't recognized 3. Frequency-Based Sorting Sort predictions by how often the user selects them