UserDictionaryManager udm =
String locale = TextAnalyzerConstant.LANGUAGE_ID_EN_US;
UserDictionary ud= udm.createUserDictionary(locale, ”common_1”);
ud.addUserWord(”tst”); // Add a use word
UserWord word = new UserWord();
word.userWord = ”Hello”;
word.type = UserWord.TYPE_EXCEPTION_WORD;
ud.addUserWord(word); // Add an exception word
UserWord uWord = new UserWord();
uWord.userWord = ”Pls”;
uWord.replaceWord = ”Please”;
uWord.type = UserWord.TYPE_EXCEPTION_WORD;
ud.addUserWord(uWord); // Add an auto correct word
In the above code, the application first acquires an instance of the UserDictionaryManager
interface, and creates a user dictionary to get an instance of UserDictionary
. Of course, the application can also use other methods in UserDictionaryManager
to get an instance of UserDictionary
. Next, the application can invoke the addUserWord(String word)
or addUserWord(UserWord userWord)
methods in UserDictionary
to add a word into the user dictionary. The same word cannot be added into a user dictionary. The words stored in the user dictionary are UserWord
objects. The UserWord
has two types: TYPE_USER_WORD(1)
. The number in parenthesis is the integer value for each of the types. There are thee kinds of words made by the two types:
- common user word - a UserWord object without a replaceWord value, whose type is TYPE_USER_WORD. This kind of word is commonly a misspelled word, and treated as a correct word when spell checking is performed.
- exception word - a UserWord object without a replaceWord value, whose type is TYPE_EXCEPTION_WORD. This kind of word commonly is a correct word, and treated as a misspelled word when spell checking is performed.
- auto-correction word - a UserWord object with a replaceWord value, whose type is TYPE_EXCEPTION_WORD. This kind of word can be misspelled or correct, and treated as a misspelled word. It will set a value into MisspelledWord’s autoCorrectReplacement field, for auto-correction by the application when spell checking is performed.
When an application creates a UserWord
object, the default type is TYPE_USER_WORD
. If the application wants to create an exception word or an auto-correction word, it must set the word’s type manually. Next, the application invokes removeUserWord( String word)
or removeUserWord(UserWord userWord)
to delete a user word from the user dictionary.
Parent topic: User dictionary manager