aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsatok <satok@exia.tok.corp.google.com>2010-07-16 13:02:45 +0900
committersatok <satok@exia.tok.corp.google.com>2010-07-16 13:02:45 +0900
commitb9c57e6540502ef3b2941235bbbede4dedfdcfb7 (patch)
treec8ccdc1455ab21eaef06c2b053ac7cada78de9f9 /tests
parentb5a0d8ef42d9e0be4e56be04637c167074447744 (diff)
parent2a118d844e0b7dd3e01f25e937b02b05711768a6 (diff)
downloadlatinime-b9c57e6540502ef3b2941235bbbede4dedfdcfb7.tar.gz
latinime-b9c57e6540502ef3b2941235bbbede4dedfdcfb7.tar.xz
latinime-b9c57e6540502ef3b2941235bbbede4dedfdcfb7.zip
Merge remote branch 'goog/master'
Conflicts: java/res/xml/prefs.xml java/src/com/android/inputmethod/latin/BinaryDictionary.java java/src/com/android/inputmethod/latin/Dictionary.java java/src/com/android/inputmethod/latin/ExpandableDictionary.java java/src/com/android/inputmethod/latin/LatinIME.java java/src/com/android/inputmethod/latin/Suggest.java tests/src/com/android/inputmethod/latin/tests/SuggestTests.java
Diffstat (limited to 'tests')
-rw-r--r--tests/data/bigramlist.xml36
-rw-r--r--tests/data/wordlist.xml1
-rw-r--r--tests/res/raw/test.dictbin2562 -> 2829 bytes
-rw-r--r--tests/src/com/android/inputmethod/latin/tests/SuggestTests.java67
4 files changed, 100 insertions, 4 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
index e789aaa9a..6a5d6d794 100644
--- a/tests/res/raw/test.dict
+++ b/tests/res/raw/test.dict
Binary files differ
diff --git a/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java b/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java
index 0d3babfbc..318cc7ccd 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;
}
@@ -248,4 +285,26 @@ public class SuggestTests extends AndroidTestCase {
// Mar<LATIN SMALL LETTER I WITH ACUTE>a
assertTrue(isDefaultCorrection("maria", "Mar\u00EDa"));
}
+
+ /**
+ * 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"));
+ }
}