diff options
author | 2010-06-30 20:28:04 -0700 | |
---|---|---|
committer | 2010-07-13 11:33:39 -0700 | |
commit | 937d5ad0131267aa4273f3e5d75b203a1f263c18 (patch) | |
tree | b4a3bb6206aea92f5bacc3ebc1387ffdd5916f0c /tests | |
parent | b71547f2d065a17b268d1dbc896daab1820141a6 (diff) | |
download | latinime-937d5ad0131267aa4273f3e5d75b203a1f263c18.tar.gz latinime-937d5ad0131267aa4273f3e5d75b203a1f263c18.tar.xz latinime-937d5ad0131267aa4273f3e5d75b203a1f263c18.zip |
added bigram prediction
- after first character, only suggests bigram data (but doesn't autocomplete)
- after second character, words from dictionary gets rearranged by using bigram
- compatible with old dictionary
- added preference option to disable bigram
Change-Id: Ia8f4e8fa55e797e86d858fd499887cd396388411
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/bigramlist.xml | 36 | ||||
-rw-r--r-- | tests/data/wordlist.xml | 1 | ||||
-rw-r--r-- | tests/res/raw/test.dict | bin | 2562 -> 2829 bytes | |||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/tests/SuggestTests.java | 73 |
4 files changed, 103 insertions, 7 deletions
diff --git a/tests/data/bigramlist.xml b/tests/data/bigramlist.xml new file mode 100644 index 000000000..dd3f2916e --- /dev/null +++ b/tests/data/bigramlist.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2010, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<bigrams> + <bi w1="I'm" count="1"> + <w w2="about" p="100" /> + </bi> + <bi w1="about" count="3"> + <w w2="part" p="117" /> + <w w2="business" p="100" /> + <w w2="being" p="10" /> + </bi> + <bi w1="business" count="1"> + <w w2="people" p="100" /> + </bi> + <bi w1="from" count="1"> + <w w2="same" p="117" /> + </bi> +</bigrams> diff --git a/tests/data/wordlist.xml b/tests/data/wordlist.xml index 22d0caa38..b870eb2a3 100644 --- a/tests/data/wordlist.xml +++ b/tests/data/wordlist.xml @@ -225,6 +225,7 @@ <w f="179">services</w> <w f="170">niño</w> <w f="170">MarÃa</w> + <w f="70">car</w> <w f="0">hmmm</w> <w f="0">hon</w> <w f="0">tty</w> diff --git a/tests/res/raw/test.dict b/tests/res/raw/test.dict Binary files differindex e789aaa9a..6a5d6d794 100644 --- a/tests/res/raw/test.dict +++ b/tests/res/raw/test.dict diff --git a/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java b/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java index 9401d926a..59720640a 100644 --- a/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java +++ b/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java @@ -71,7 +71,7 @@ public class SuggestTests extends AndroidTestCase { Log.w(TAG, "No available size for binary dictionary"); } mSuggest.setAutoTextEnabled(false); - mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL); + mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM); } /************************** Helper functions ************************/ @@ -108,19 +108,56 @@ public class SuggestTests extends AndroidTestCase { private boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) { WordComposer word = createWordComposer(typed); - List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null); + return isDefaultSuggestion(suggestions, expected); + } + + private void getBigramSuggestions(CharSequence previous, CharSequence typed) { + if(!TextUtils.isEmpty(previous) && (typed.length() > 1)) { + WordComposer firstChar = createWordComposer(typed.charAt(0) + ""); + mSuggest.getSuggestions(null, firstChar, false, previous); + } + } + + private boolean isDefaultNextSuggestion(CharSequence previous, CharSequence typed, + CharSequence expected) { + WordComposer word = createWordComposer(typed); + getBigramSuggestions(previous, typed); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous); return isDefaultSuggestion(suggestions, expected); } private boolean isDefaultCorrection(CharSequence typed, CharSequence expected) { WordComposer word = createWordComposer(typed); - List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null); + return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection(); + } + + private boolean isDefaultNextCorrection(CharSequence previous, CharSequence typed, + CharSequence expected) { + WordComposer word = createWordComposer(typed); + getBigramSuggestions(previous, typed); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous); + for(int i=0;i<suggestions.size();i++) { + Log.i(TAG,i+" "+suggestions.get(i)); + } return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection(); } private boolean isASuggestion(CharSequence typed, CharSequence expected) { WordComposer word = createWordComposer(typed); - List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null); + for (int i = 1; i < suggestions.size(); i++) { + if (TextUtils.equals(suggestions.get(i), expected)) return true; + } + return false; + } + + private boolean isASuggestion(CharSequence previous, CharSequence typed, + CharSequence expected) { + WordComposer word = createWordComposer(typed); + getBigramSuggestions(previous, typed); + List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous); for (int i = 1; i < suggestions.size(); i++) { if (TextUtils.equals(suggestions.get(i), expected)) return true; } @@ -241,8 +278,30 @@ public class SuggestTests extends AndroidTestCase { * Are accented forms of words suggested as corrections? */ public void testAccents() { - assertTrue(isDefaultCorrection("nino", "ni\u00F1o")); // ni–o - assertTrue(isDefaultCorrection("nimo", "ni\u00F1o")); // ni–o - assertTrue(isDefaultCorrection("maria", "Mar\u00EDa")); // Mar’a + assertTrue(isDefaultCorrection("nino", "ni\u00F1o")); // niño + assertTrue(isDefaultCorrection("nimo", "ni\u00F1o")); // niño + assertTrue(isDefaultCorrection("maria", "Mar\u00EDa")); // MarÃa + } + + /** + * Make sure bigrams are showing when first character is typed + * and don't show any when there aren't any + */ + public void testBigramsAtFirstChar() { + assertTrue(isDefaultNextCorrection("about", "p", "part")); + assertTrue(isDefaultNextCorrection("I'm", "a", "about")); + assertTrue(isDefaultNextCorrection("about", "b", "business")); + assertTrue(isASuggestion("about", "b", "being")); + assertFalse(isDefaultNextSuggestion("about", "p", "business")); + } + + /** + * Make sure bigrams score affects the original score + */ + public void testBigramsScoreEffect() { + assertTrue(isDefaultCorrection("pa", "page")); + assertTrue(isDefaultNextCorrection("about", "pa", "part")); + assertTrue(isDefaultCorrection("sa", "said")); + assertTrue(isDefaultNextCorrection("from", "sa", "same")); } } |