Dictionary based auto suggestions in Android IME

Dictionanry-based sentences are displayed in the IME candidate view when we start typing in the textview editor. For example, if we type "th" in the textview, then words like "this", "that", "the", "there", etc. will be displayed. I am trying to find out from a repo source from Android how these dictionary based sentences are retrieved internally. Has anyone tried to investigate this?

+3


source to share


1 answer


I started building an android IME solution myself and I am using two things for my auto complete and suggestions. Not sure how this will help you or anyone. But this is what I did ...

I used user_dict.db as a template database from the /data/data/com.android.providers.userdictionary/databases directory. I searched for the most common English words and imported them into the database. I made a simple database query for words like what the user was typing into the new AsyncTask. Also, when the user makes a "space" to complete a word, I used Jazzy, which is an apllchecker api for Java, and I took the data from InputConnection and sent it to Jazzy for verification. If the api came up with at least two results, I would replace the user word with the first Jazzy result.

Here are some of the code I used to create the offer list.



ArrayList<String> list = new ArrayList<String>();

.....AsyncTask.......
protected String doInBackground(String... str) {
                list.clear();
            list.add(totalString); // this is the string 
                                   //captured from InputConnection
                Cursor c = db.getNameTitle(totalString); //this is my method in my Database 
//adapter that queries the database and returns a limit of 30 results
                        if(c.moveToFirst()){
                            for(int i = 0; i < c.getCount(); i++){
                                list.add(c.getString(c.getColumnIndex(DBAdapter2.KEY_WORD)));
                                if(c.getCount() != i){
                                    c.moveToNext();
                                }
                            }
                        }
                        c.close();
}

protected void onPostExecute(String result) {
         mCandidateView.clear();
         mCandidateView.setCandidatesViewShown(false);
         Log.i("TAG", String.valueOf(list.size()));
         if(list.size() > 0 && list.size() < 32){
             mCandidateView.setSuggestions(list, true, true);//CandidateView similar to the SDK example of SoftKeyboard or LatinIME
         }
}

      

Hope this helps anyone. There may be another way to do this, but these words are great and fast. You may need to find the best query that suits your needs.

+1


source







All Articles