aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJae Yong Sung <jysung@google.com>2010-07-26 11:43:29 -0700
committerJae Yong Sung <jysung@google.com>2010-07-28 11:08:08 -0700
commit80aa14fd432cf7d2c67f2fcfcc57c80f29f8eb64 (patch)
tree384655d5c7207325014888fd26da1bc7188db66e /tests
parent679b838b05a70ed965017635efdf536449aa230f (diff)
downloadlatinime-80aa14fd432cf7d2c67f2fcfcc57c80f29f8eb64.tar.gz
latinime-80aa14fd432cf7d2c67f2fcfcc57c80f29f8eb64.tar.xz
latinime-80aa14fd432cf7d2c67f2fcfcc57c80f29f8eb64.zip
- separate dict (uses xml)
- retrieve bigrams that only starts with character typed and neighbor keys - contacts bigram - performance measure bug: 2873133 Change-Id: If97c005b18c82f3fafef50009dd2dfd972b0ab8f
Diffstat (limited to 'tests')
-rw-r--r--tests/res/raw/testtext.txt24
-rw-r--r--tests/src/com/android/inputmethod/latin/tests/SuggestHelper.java192
-rw-r--r--tests/src/com/android/inputmethod/latin/tests/SuggestPerformanceTests.java127
-rw-r--r--tests/src/com/android/inputmethod/latin/tests/SuggestTests.java264
4 files changed, 406 insertions, 201 deletions
diff --git a/tests/res/raw/testtext.txt b/tests/res/raw/testtext.txt
new file mode 100644
index 000000000..eca20c05f
--- /dev/null
+++ b/tests/res/raw/testtext.txt
@@ -0,0 +1,24 @@
+This text is used as test text for measuring performance of dictionary prediction. Any text can be put into this file to test the performance (total keystroke savings).
+When you think about “information,” what probably comes to mind are streams of words and numbers. Google’s pretty good at organizing these types of information, but consider all the things you can’t express with words: what does it look like in the middle of a sandstorm? What are some great examples of Art Nouveau architecture? Should I consider wedding cupcakes instead of a traditional cake?
+This is why we built Google Images in 2001. We realized that for many searches, the best answer wasn’t text—it was an image or a set of images. The service has grown quite a bit since then. In 2001, we indexed around 250 million images. By 2005, we had indexed over 1 billion. And today, we have an index of over 10 billion images.
+It’s not just about quantity, though. Over the past decade we’ve been baking deep computer science into Google Images to make it even faster and easier for you to find precisely the right images. We not only find images for pretty much anything you type in; we can also instantly pull out images of clip art, line drawings, faces and even colors.
+There’s even more sophisticated computer vision technology powering our “Similar images” tool. For example, did you know there are nine subspecies of leopards, each with a distinct pattern of spots? Google Images can recognize the difference, returning just leopards of a particular subspecies. It can tell you the name of the subspecies in a particular image—even if that image isn’t labeled—because other similar leopard images on the web are labeled with that subspecies’s name.
+And our “Similar colors” refinement doesn’t just return images based on the overall color of an image. If it did, lots of images would simply be classified as “white.” If you’re looking for [tulips] and you refine results to “white,” you really want images in which the tulips themselves are white—not the surrounding image. It takes some heavy-duty algorithmic wizardry and processing power for a search engine to understand what the items of interest are in all the images out there.
+Those are just a few of the technologies we’ve built to make Google Images more useful. Meanwhile, the quantity and variety of images on the web has ballooned since 2001, and images have become one of the most popular types of content people search for. So over the next few days we’re rolling out an update to Google Images to match the scope and beauty of this fast-growing visual web, and to bring to the surface some of the powerful technology behind Images.
+Here’s what’s new in this refreshed design of Google Images:
+Dense tiled layout designed to make it easy to look at lots of images at once. We want to get the app out of the way so you can find what you’re really looking for.
+Instant scrolling between pages, without letting you get lost in the images. You can now get up to 1,000 images, all in one scrolling page. And we’ll show small, unobtrusive page numbers so you don’t lose track of where you are.
+Larger thumbnail previews on the results page, designed for modern browsers and high-res screens.
+A hover pane that appears when you mouse over a given thumbnail image, giving you a larger preview, more info about the image and other image-specific features such as “Similar images.”
+Once you click on an image, you’re taken to a new landing page that displays a large image in context, with the website it’s hosted on visible right behind it. Click anywhere outside the image, and you’re right in the original page where you can learn more about the source and context.
+Optimized keyboard navigation for faster scrolling through many pages, taking advantage of standard web keyboard shortcuts such as Page Up / Page Down. It’s all about getting you to the info you need quickly, so you can get on with actually building that treehouse or buying those flowers.
+Apple's not really ready to say it's sorry about the iPhone 4 antenna design, but it is willing to give all you darn squeaky wheels free cases for your trouble. Since Apple can't build its own Bumpers fast enough, it will give you a few options and let you decide, then send it your way for free as long as you purchased the phone before September 30th. Not good enough for you? Well, if you already bought a bumper from Apple you'll get a refund, and you can also return your phone for a full refund within 30 days as long as it's unharmed.
+This solution comes at the end of 22 days of Apple engineers "working their butts off," according to Steve, with "physics" ultimately being pinned as the main culprit. Apple claims you can replicate the left-handed "death grip" bar-dropping problem on the BlackBerry Bold 9700, HTC Droid Eris, and Samsung Omnia II, and that "phones aren't perfect." Steve also claims that only 0.55% of people who bought the iPhone 4 have called into AppleCare to complain about the antenna, and the phone has a 1.7% return rate at AT&T, compared to 6% with the 3GS, though he would cop to a slight increase in dropped calls over the iPhone 3GS. For this Steve has what he confesses to be a pet theory: that 3GS users were using the case they had from the 3G, and therefore weren't met with the horrible reality of a naked, call dropping handset. Hence the free case solution, which will probably satisfy some, infuriate others, and never even blip onto the radar of many of the massive horde of consumers that's devoured this product in unprecedented numbers.
+Update: Our own Richard Lai just waltzed down to the Regent Street Apple Store in London with his iPhone Bumper receipt in hand. A few minutes later he left with cold, hard cash, and kept the Bumper to boot. Seems as if the refund effort is a go, at least over in the UK.
+Update 2: We've heard from several tipsters saying Apple no longer does Bumper refunds at its stores; customers will now have to make an online claim instead. Looks like we got super lucky.
+If you have ever received an instant message, text message, or any text-based chat message that seemed to be written in a foreign language, this Webopedia Quick Reference will help you decipher the text chat lingo by providing the definitions to more than 1,300 chat, text message, and Twitter abbreviations.
+With the popularity and rise in real-time text-based communications, such as Facebook, Twitter, instant messaging, e-mail, Internet and online gaming services, chat rooms, discussion boards and mobile phone text messaging (SMS), came the emergence of a new language tailored to the immediacy and compactness of these new communication media.
+While it does seem incredible that there are so many chat abbreviations, remember that different chat abbreviations are used by different groups of people when communicating online. Some of the following chat abbreviations may be familiar to you, while others may be foreign because they are used by a group of people with different online interests and hobbies than your own. For example, people playing online games are likely to use chat abbreviations that are different than those used by someone running a financial blog updating their Twitter status.
+Twitter is a free microblog, or social messaging tool that lets people stay connected through brief text message updates up to 140 characters in length. Twitter is based on you answering the question "What are you doing?" You then post thoughts, observations and goings-on during the day in answer to that question. Your update is posted on your Twitter profile page through SMS text messaging, the Twitter Web site, instant messaging, RSS, e-mail or through other social applications and sites, such as Facebook.
+As with any new social medium, there is an entire vocabulary that users of the Twitter service adopt. Many of the new lingo Twitter-based terms and phrases are used to describe the collection of people who use the service, while other terms are used in reference to describe specific functions and features of the service itself. Also, there are a number of "chat terms," which are basically shorthand abbreviations that users often include in their tweets. Lastly, our guide also provides descriptions to a number of Twitter tools and applications that you can use to enhance your Twitter experience.
+Here are definitions to more than 100 Twitter-related abbreviations, words, phrases, and tools that are associated with the Twitter microblogging service. If you know of a Twitter slang term or application name that is not included in our Twitter Dictionary, please let us know.
diff --git a/tests/src/com/android/inputmethod/latin/tests/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/tests/SuggestHelper.java
new file mode 100644
index 000000000..e3e995a23
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/tests/SuggestHelper.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package com.android.inputmethod.latin.tests;
+
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.text.TextUtils;
+import android.util.Log;
+import com.android.inputmethod.latin.Suggest;
+import com.android.inputmethod.latin.WordComposer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.Channels;
+import java.util.List;
+
+public class SuggestHelper {
+ private Suggest mSuggest;
+ private final String TAG;
+
+ public SuggestHelper(String tag, Context context, int[] resId) {
+ TAG = tag;
+ try {
+ // merging separated dictionary into one if dictionary is separated
+ int total = 0;
+ InputStream[] res = new InputStream[resId.length];
+ for (int i = 0; i < resId.length; i++) {
+ res[i] = context.getResources().openRawResource(resId[i]);
+ total += res[i].available();
+ }
+
+ ByteBuffer byteBuffer =
+ ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder());
+ int got = 0;
+ for (int i = 0; i < resId.length; i++) {
+ got += Channels.newChannel(res[i]).read(byteBuffer);
+ }
+ if (got != total) {
+ Log.w(TAG, "Read " + got + " bytes, expected " + total);
+ } else {
+ mSuggest = new Suggest(context, byteBuffer);
+ Log.i(TAG, "Created mSuggest " + total + " bytes");
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "No available memory for binary dictionary");
+ } finally {
+ try {
+ for (int i = 0;i < is.length; i++) {
+ res[i].close();
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "Failed to close input stream");
+ }
+ }
+ mSuggest.setAutoTextEnabled(false);
+ mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
+ }
+
+ private WordComposer createWordComposer(CharSequence s) {
+ WordComposer word = new WordComposer();
+ for (int i = 0; i < s.length(); i++) {
+ final char c = s.charAt(i);
+ int[] codes;
+ // If it's not a lowercase letter, don't find adjacent letters
+ if (c < 'a' || c > 'z') {
+ codes = new int[] { c };
+ } else {
+ codes = adjacents[c - 'a'];
+ }
+ word.add(c, codes);
+ }
+ return word;
+ }
+
+ private void showList(String title, List<CharSequence> suggestions) {
+ Log.i(TAG, title);
+ for (int i = 0; i < suggestions.size(); i++) {
+ Log.i(title, suggestions.get(i) + ", ");
+ }
+ }
+
+ private boolean isDefaultSuggestion(List<CharSequence> suggestions, CharSequence word) {
+ // Check if either the word is what you typed or the first alternative
+ return suggestions.size() > 0 &&
+ (/*TextUtils.equals(suggestions.get(0), word) || */
+ (suggestions.size() > 1 && TextUtils.equals(suggestions.get(1), word)));
+ }
+
+ boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) {
+ WordComposer word = createWordComposer(typed);
+ List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null);
+ return isDefaultSuggestion(suggestions, expected);
+ }
+
+ boolean isDefaultCorrection(CharSequence typed, CharSequence expected) {
+ WordComposer word = createWordComposer(typed);
+ List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null);
+ return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
+ }
+
+ boolean isASuggestion(CharSequence typed, CharSequence expected) {
+ WordComposer word = createWordComposer(typed);
+ 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 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);
+ }
+ }
+
+ 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);
+ }
+
+ boolean isDefaultNextCorrection(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) && mSuggest.hasMinimalCorrection();
+ }
+
+ 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;
+ }
+ return false;
+ }
+
+ boolean isValid(CharSequence typed) {
+ return mSuggest.isValidWord(typed);
+ }
+
+ final int[][] adjacents = {
+ {'a','s','w','q',-1},
+ {'b','h','v','n','g','j',-1},
+ {'c','v','f','x','g',},
+ {'d','f','r','e','s','x',-1},
+ {'e','w','r','s','d',-1},
+ {'f','g','d','c','t','r',-1},
+ {'g','h','f','y','t','v',-1},
+ {'h','j','u','g','b','y',-1},
+ {'i','o','u','k',-1},
+ {'j','k','i','h','u','n',-1},
+ {'k','l','o','j','i','m',-1},
+ {'l','k','o','p',-1},
+ {'m','k','n','l',-1},
+ {'n','m','j','k','b',-1},
+ {'o','p','i','l',-1},
+ {'p','o',-1},
+ {'q','w',-1},
+ {'r','t','e','f',-1},
+ {'s','d','e','w','a','z',-1},
+ {'t','y','r',-1},
+ {'u','y','i','h','j',-1},
+ {'v','b','g','c','h',-1},
+ {'w','e','q',-1},
+ {'x','c','d','z','f',-1},
+ {'y','u','t','h','g',-1},
+ {'z','s','x','a','d',-1},
+ };
+}
diff --git a/tests/src/com/android/inputmethod/latin/tests/SuggestPerformanceTests.java b/tests/src/com/android/inputmethod/latin/tests/SuggestPerformanceTests.java
new file mode 100644
index 000000000..473c440f9
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/tests/SuggestPerformanceTests.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package com.android.inputmethod.latin.tests;
+
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+public class SuggestPerformanceTests extends AndroidTestCase {
+ private static final String TAG = "SuggestPerformanceTests";
+
+ private String mTestText;
+ private SuggestHelper sh;
+
+ @Override
+ protected void setUp() {
+ // TODO Figure out a way to directly using the dictionary rather than copying it over
+
+ // For testing with real dictionary, TEMPORARILY COPY main dictionary into test directory.
+ // DO NOT SUBMIT real dictionary under test directory.
+ //int[] resId = new int[] { R.raw.main0, R.raw.main1, R.raw.main2 };
+
+ int[] resId = new int[] { R.raw.test };
+
+ sh = new SuggestHelper(TAG, getTestContext(), resId);
+ loadString();
+ }
+
+ private void loadString() {
+ try {
+ InputStream is = getTestContext().getResources().openRawResource(R.raw.testtext);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
+ String line = reader.readLine();
+ while (line != null) {
+ sb.append(line + " ");
+ line = reader.readLine();
+ }
+ mTestText = sb.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /************************** Helper functions ************************/
+ private int lookForSuggestion(String prevWord, String currentWord) {
+ for (int i = 1; i < currentWord.length(); i++) {
+ if (i == 1) {
+ if (sh.isDefaultNextSuggestion(prevWord, currentWord.substring(0, i),
+ currentWord)) {
+ return i;
+ }
+ } else {
+ if (sh.isDefaultNextCorrection(prevWord, currentWord.substring(0, i),
+ currentWord)) {
+ return i;
+ }
+ }
+ }
+ return currentWord.length();
+ }
+
+ private double runText(boolean withBigrams) {
+ StringTokenizer st = new StringTokenizer(mTestText);
+ String prevWord = null;
+ int typeCount = 0;
+ int characterCount = 0; // without space
+ int wordCount = 0;
+ while (st.hasMoreTokens()) {
+ String currentWord = st.nextToken();
+ boolean endCheck = false;
+ if (currentWord.matches("[\\w]*[\\.|?|!|*|@|&|/|:|;]")) {
+ currentWord = currentWord.substring(0, currentWord.length() - 1);
+ endCheck = true;
+ }
+ if (withBigrams && prevWord != null) {
+ typeCount += lookForSuggestion(prevWord, currentWord);
+ } else {
+ typeCount += lookForSuggestion(null, currentWord);
+ }
+ characterCount += currentWord.length();
+ if (!endCheck) prevWord = currentWord;
+ wordCount++;
+ }
+
+ double result = (double) (characterCount - typeCount) / characterCount * 100;
+ if (withBigrams) {
+ Log.i(TAG, "with bigrams -> " + result + " % saved!");
+ } else {
+ Log.i(TAG, "without bigrams -> " + result + " % saved!");
+ }
+ Log.i(TAG, "\ttotal number of words: " + wordCount);
+ Log.i(TAG, "\ttotal number of characters: " + mTestText.length());
+ Log.i(TAG, "\ttotal number of characters without space: " + characterCount);
+ Log.i(TAG, "\ttotal number of characters typed: " + typeCount);
+ return result;
+ }
+
+
+ /************************** Performance Tests ************************/
+ /**
+ * Compare the Suggest with and without bigram
+ * Check the log for detail
+ */
+ public void testSuggestPerformance() {
+ assertTrue(runText(false) < runText(true));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java b/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java
index 318cc7ccd..a42422b91 100644
--- a/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java
+++ b/tests/src/com/android/inputmethod/latin/tests/SuggestTests.java
@@ -1,171 +1,33 @@
-package com.android.inputmethod.latin.tests;
+/*
+ * Copyright (C) 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.
+ */
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.channels.Channels;
-import java.util.List;
+package com.android.inputmethod.latin.tests;
-import android.content.Context;
import android.test.AndroidTestCase;
-import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.latin.Suggest;
-import com.android.inputmethod.latin.WordComposer;
-
public class SuggestTests extends AndroidTestCase {
private static final String TAG = "SuggestTests";
- private Suggest mSuggest;
-
- int[][] adjacents = {
- {'a','s','w','q',-1},
- {'b','h','v','n','g','j',-1},
- {'c','v','f','x','g',},
- {'d','f','r','e','s','x',-1},
- {'e','w','r','s','d',-1},
- {'f','g','d','c','t','r',-1},
- {'g','h','f','y','t','v',-1},
- {'h','j','u','g','b','y',-1},
- {'i','o','u','k',-1},
- {'j','k','i','h','u','n',-1},
- {'k','l','o','j','i','m',-1},
- {'l','k','o','p',-1},
- {'m','k','n','l',-1},
- {'n','m','j','k','b',-1},
- {'o','p','i','l',-1},
- {'p','o',-1},
- {'q','w',-1},
- {'r','t','e','f',-1},
- {'s','d','e','w','a','z',-1},
- {'t','y','r',-1},
- {'u','y','i','h','j',-1},
- {'v','b','g','c','h',-1},
- {'w','e','q',-1},
- {'x','c','d','z','f',-1},
- {'y','u','t','h','g',-1},
- {'z','s','x','a','d',-1},
- };
+ private SuggestHelper sh;
@Override
protected void setUp() {
- final Context context = getTestContext();
- InputStream is = context.getResources().openRawResource(R.raw.test);
- Log.i(TAG, "Stream type is " + is);
- try {
- int avail = is.available();
- if (avail > 0) {
- ByteBuffer byteBuffer =
- ByteBuffer.allocateDirect(avail).order(ByteOrder.nativeOrder());
- int got = Channels.newChannel(is).read(byteBuffer);
- if (got != avail) {
- Log.e(TAG, "Read " + got + " bytes, expected " + avail);
- } else {
- mSuggest = new Suggest(context, byteBuffer);
- Log.i(TAG, "Created mSuggest " + avail + " bytes");
- }
- }
- } catch (IOException ioe) {
- Log.w(TAG, "No available size for binary dictionary");
- }
- mSuggest.setAutoTextEnabled(false);
- mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
- }
-
- /************************** Helper functions ************************/
-
- private WordComposer createWordComposer(CharSequence s) {
- WordComposer word = new WordComposer();
- for (int i = 0; i < s.length(); i++) {
- final char c = s.charAt(i);
- int[] codes;
- // If it's not a lowercase letter, don't find adjacent letters
- if (c < 'a' || c > 'z') {
- codes = new int[] { c };
- } else {
- codes = adjacents[c - 'a'];
- }
- word.add(c, codes);
- }
- return word;
- }
-
- private void showList(String title, List<CharSequence> suggestions) {
- Log.i(TAG, title);
- for (int i = 0; i < suggestions.size(); i++) {
- Log.i(title, suggestions.get(i) + ", ");
- }
- }
-
- private boolean isDefaultSuggestion(List<CharSequence> suggestions, CharSequence word) {
- // Check if either the word is what you typed or the first alternative
- return suggestions.size() > 0 &&
- (/*TextUtils.equals(suggestions.get(0), word) || */
- (suggestions.size() > 1 && TextUtils.equals(suggestions.get(1), word)));
- }
-
- private boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) {
- WordComposer word = createWordComposer(typed);
- 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, 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, 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;
- }
- return false;
- }
-
- private boolean isValid(CharSequence typed) {
- return mSuggest.isValidWord(typed);
+ int[] resId = new int[] { R.raw.test };
+ sh = new SuggestHelper(TAG, getTestContext(), resId);
}
/************************** Tests ************************/
@@ -174,87 +36,87 @@ public class SuggestTests extends AndroidTestCase {
* Tests for simple completions of one character.
*/
public void testCompletion1char() {
- assertTrue(isDefaultSuggestion("peopl", "people"));
- assertTrue(isDefaultSuggestion("abou", "about"));
- assertTrue(isDefaultSuggestion("thei", "their"));
+ assertTrue(sh.isDefaultSuggestion("peopl", "people"));
+ assertTrue(sh.isDefaultSuggestion("abou", "about"));
+ assertTrue(sh.isDefaultSuggestion("thei", "their"));
}
/**
* Tests for simple completions of two characters.
*/
public void testCompletion2char() {
- assertTrue(isDefaultSuggestion("peop", "people"));
- assertTrue(isDefaultSuggestion("calli", "calling"));
- assertTrue(isDefaultSuggestion("busine", "business"));
+ assertTrue(sh.isDefaultSuggestion("peop", "people"));
+ assertTrue(sh.isDefaultSuggestion("calli", "calling"));
+ assertTrue(sh.isDefaultSuggestion("busine", "business"));
}
/**
* Tests for proximity errors.
*/
public void testProximityPositive() {
- assertTrue(isDefaultSuggestion("peiple", "people"));
- assertTrue(isDefaultSuggestion("peoole", "people"));
- assertTrue(isDefaultSuggestion("pwpple", "people"));
+ assertTrue(sh.isDefaultSuggestion("peiple", "people"));
+ assertTrue(sh.isDefaultSuggestion("peoole", "people"));
+ assertTrue(sh.isDefaultSuggestion("pwpple", "people"));
}
/**
* Tests for proximity errors - negative, when the error key is not near.
*/
public void testProximityNegative() {
- assertFalse(isDefaultSuggestion("arout", "about"));
- assertFalse(isDefaultSuggestion("ire", "are"));
+ assertFalse(sh.isDefaultSuggestion("arout", "about"));
+ assertFalse(sh.isDefaultSuggestion("ire", "are"));
}
/**
* Tests for checking if apostrophes are added automatically.
*/
public void testApostropheInsertion() {
- assertTrue(isDefaultSuggestion("im", "I'm"));
- assertTrue(isDefaultSuggestion("dont", "don't"));
+ assertTrue(sh.isDefaultSuggestion("im", "I'm"));
+ assertTrue(sh.isDefaultSuggestion("dont", "don't"));
}
/**
* Test to make sure apostrophed word is not suggested for an apostrophed word.
*/
public void testApostrophe() {
- assertFalse(isDefaultSuggestion("don't", "don't"));
+ assertFalse(sh.isDefaultSuggestion("don't", "don't"));
}
/**
* Tests for suggestion of capitalized version of a word.
*/
public void testCapitalization() {
- assertTrue(isDefaultSuggestion("i'm", "I'm"));
- assertTrue(isDefaultSuggestion("sunday", "Sunday"));
- assertTrue(isDefaultSuggestion("sundat", "Sunday"));
+ assertTrue(sh.isDefaultSuggestion("i'm", "I'm"));
+ assertTrue(sh.isDefaultSuggestion("sunday", "Sunday"));
+ assertTrue(sh.isDefaultSuggestion("sundat", "Sunday"));
}
/**
* Tests to see if more than one completion is provided for certain prefixes.
*/
public void testMultipleCompletions() {
- assertTrue(isASuggestion("com", "come"));
- assertTrue(isASuggestion("com", "company"));
- assertTrue(isASuggestion("th", "the"));
- assertTrue(isASuggestion("th", "that"));
- assertTrue(isASuggestion("th", "this"));
- assertTrue(isASuggestion("th", "they"));
+ assertTrue(sh.isASuggestion("com", "come"));
+ assertTrue(sh.isASuggestion("com", "company"));
+ assertTrue(sh.isASuggestion("th", "the"));
+ assertTrue(sh.isASuggestion("th", "that"));
+ assertTrue(sh.isASuggestion("th", "this"));
+ assertTrue(sh.isASuggestion("th", "they"));
}
/**
* Does the suggestion engine recognize zero frequency words as valid words.
*/
public void testZeroFrequencyAccepted() {
- assertTrue(isValid("yikes"));
- assertFalse(isValid("yike"));
+ assertTrue(sh.isValid("yikes"));
+ assertFalse(sh.isValid("yike"));
}
/**
* Tests to make sure that zero frequency words are not suggested as completions.
*/
public void testZeroFrequencySuggestionsNegative() {
- assertFalse(isASuggestion("yike", "yikes"));
- assertFalse(isASuggestion("what", "whatcha"));
+ assertFalse(sh.isASuggestion("yike", "yikes"));
+ assertFalse(sh.isASuggestion("what", "whatcha"));
}
/**
@@ -262,16 +124,16 @@ public class SuggestTests extends AndroidTestCase {
* and not considered corrections, in some cases.
*/
public void testTooLargeEditDistance() {
- assertFalse(isASuggestion("sniyr", "about"));
- assertFalse(isDefaultCorrection("rjw", "the"));
+ assertFalse(sh.isASuggestion("sniyr", "about"));
+ assertFalse(sh.isDefaultCorrection("rjw", "the"));
}
/**
- * Make sure isValid is case-sensitive.
+ * Make sure sh.isValid is case-sensitive.
*/
public void testValidityCaseSensitivity() {
- assertTrue(isValid("Sunday"));
- assertFalse(isValid("sunday"));
+ assertTrue(sh.isValid("Sunday"));
+ assertFalse(sh.isValid("sunday"));
}
/**
@@ -279,11 +141,11 @@ public class SuggestTests extends AndroidTestCase {
*/
public void testAccents() {
// ni<LATIN SMALL LETTER N WITH TILDE>o
- assertTrue(isDefaultCorrection("nino", "ni\u00F1o"));
+ assertTrue(sh.isDefaultCorrection("nino", "ni\u00F1o"));
// ni<LATIN SMALL LETTER N WITH TILDE>o
- assertTrue(isDefaultCorrection("nimo", "ni\u00F1o"));
+ assertTrue(sh.isDefaultCorrection("nimo", "ni\u00F1o"));
// Mar<LATIN SMALL LETTER I WITH ACUTE>a
- assertTrue(isDefaultCorrection("maria", "Mar\u00EDa"));
+ assertTrue(sh.isDefaultCorrection("maria", "Mar\u00EDa"));
}
/**
@@ -291,20 +153,20 @@ public class SuggestTests extends AndroidTestCase {
* 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"));
+ assertTrue(sh.isDefaultNextSuggestion("about", "p", "part"));
+ assertTrue(sh.isDefaultNextSuggestion("I'm", "a", "about"));
+ assertTrue(sh.isDefaultNextSuggestion("about", "b", "business"));
+ assertTrue(sh.isASuggestion("about", "b", "being"));
+ assertFalse(sh.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"));
+ assertTrue(sh.isDefaultCorrection("pa", "page"));
+ assertTrue(sh.isDefaultNextCorrection("about", "pa", "part"));
+ assertTrue(sh.isDefaultCorrection("sa", "said"));
+ assertTrue(sh.isDefaultNextCorrection("from", "sa", "same"));
}
}