I got this search string logged today ‘DRAW HEURISTICS FOR T9 DICTIONARY SEARCH’. Must be related to this post.
The algorithm to suggest words in T9 mode is very simple. All you need is a dictionary which stores the number sequence of keys pressed. For example, pressing 4663 can give you these six words: good, home. gone, hood, hoof, hone. The way it should work is to:
1- Store the currently typed number
2- Use it as the key to index the dictionary and get the list of all possible words that can be formed by that number sequence.
3- When the action key is pressed, cycle through that list. Start over.
Let’s say you want to simulate the functionality in a C++ application, here is now you would proceed.
// This code is utterly buggy, entirely untested, written out of the top of my head, in 10 minutes, using notepad, never seen a compiler in its life, some syntax may even be only valid in C# as my exposure to C++ these days is very limited. Use with your own responsibility.
using namespace std;
map< string , vector< string > > get_data( );
vector< wstring > current_list;
map< string , vector< wstring > > t9_dictionary;
void reset_list( )
if( t9_dictionary.size( ) )
current_list = t9_dictionary.begin( ).first;
: t9_dictionary( get_data( ) )
void add_word( const wstring& word )
if( find( current_list.begin( ) , current_list.end( ) , word ) == current_list.end( ) )
current_list.push_back( word );
void update_list( const string& current_number )
if( t9_dictionary.find( current_number ) == t9_dictionary.end( ) )
t9_dictionary [ current_number ] = vector< wstring >( );
current_list = t9_dictionary [ current_number ];
wstring& get_next_word( )
if( index < current_list.size( ) )
return current_list [ size ];
index = 0;
if( current_list.size( ) )
return current_list [ index ];