aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-09-18 05:09:41 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-18 05:09:41 +0000
commit0f9bf787962edbd10ab0d3ffe3b13af9543737d9 (patch)
treea7f84e6c9c13fc534aa3d19e0bb0296f054f8b4a /java/src/com
parentc113fde9bbe07a54e63a7825fcf44810ad1154dd (diff)
parentace9c1485251ef63f37e5cde4fc5f6d7620f3386 (diff)
downloadlatinime-0f9bf787962edbd10ab0d3ffe3b13af9543737d9.tar.gz
latinime-0f9bf787962edbd10ab0d3ffe3b13af9543737d9.tar.xz
latinime-0f9bf787962edbd10ab0d3ffe3b13af9543737d9.zip
am ace9c148: Merge "Use PrevWordsInfo.getPrevWordCount() in Java side."
* commit 'ace9c1485251ef63f37e5cde4fc5f6d7620f3386': Use PrevWordsInfo.getPrevWordCount() in Java side.
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java15
-rw-r--r--java/src/com/android/inputmethod/latin/PrevWordsInfo.java23
2 files changed, 18 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 2e108756e..8b13bdb02 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -358,9 +358,8 @@ public final class BinaryDictionary extends Dictionary {
if (!prevWordsInfo.isValid() || TextUtils.isEmpty(word)) {
return NOT_A_PROBABILITY;
}
- final int[][] prevWordCodePointArrays = new int[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM][];
- final boolean[] isBeginningOfSentenceArray =
- new boolean[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
+ final int[][] prevWordCodePointArrays = new int[prevWordsInfo.getPrevWordCount()][];
+ final boolean[] isBeginningOfSentenceArray = new boolean[prevWordsInfo.getPrevWordCount()];
prevWordsInfo.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
final int[] wordCodePoints = StringUtils.toCodePointArray(word);
return getNgramProbabilityNative(mNativeDict, prevWordCodePointArrays,
@@ -455,9 +454,8 @@ public final class BinaryDictionary extends Dictionary {
if (!prevWordsInfo.isValid() || TextUtils.isEmpty(word)) {
return false;
}
- final int[][] prevWordCodePointArrays = new int[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM][];
- final boolean[] isBeginningOfSentenceArray =
- new boolean[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
+ final int[][] prevWordCodePointArrays = new int[prevWordsInfo.getPrevWordCount()][];
+ final boolean[] isBeginningOfSentenceArray = new boolean[prevWordsInfo.getPrevWordCount()];
prevWordsInfo.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
final int[] wordCodePoints = StringUtils.toCodePointArray(word);
if (!addNgramEntryNative(mNativeDict, prevWordCodePointArrays,
@@ -473,9 +471,8 @@ public final class BinaryDictionary extends Dictionary {
if (!prevWordsInfo.isValid() || TextUtils.isEmpty(word)) {
return false;
}
- final int[][] prevWordCodePointArrays = new int[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM][];
- final boolean[] isBeginningOfSentenceArray =
- new boolean[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
+ final int[][] prevWordCodePointArrays = new int[prevWordsInfo.getPrevWordCount()][];
+ final boolean[] isBeginningOfSentenceArray = new boolean[prevWordsInfo.getPrevWordCount()];
prevWordsInfo.outputToArray(prevWordCodePointArrays, isBeginningOfSentenceArray);
final int[] wordCodePoints = StringUtils.toCodePointArray(word);
if (!removeNgramEntryNative(mNativeDict, prevWordCodePointArrays,
diff --git a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
index db877ab7a..d662051d9 100644
--- a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
+++ b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
@@ -86,33 +86,30 @@ public class PrevWordsInfo {
// For simplicity of implementation, elements may also be EMPTY_WORD_INFO transiently after the
// WordComposer was reset and before starting a new composing word, but we should never be
// calling getSuggetions* in this situation.
- public WordInfo[] mPrevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
+ public final WordInfo[] mPrevWordsInfo;
// Construct from the previous word information.
public PrevWordsInfo(final WordInfo prevWordInfo) {
- mPrevWordsInfo[0] = prevWordInfo;
+ mPrevWordsInfo = new WordInfo[] { prevWordInfo };
}
// Construct from WordInfo array. n-th element represents (n+1)-th previous word's information.
public PrevWordsInfo(final WordInfo[] prevWordsInfo) {
- for (int i = 0; i < Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM; i++) {
- mPrevWordsInfo[i] =
- (prevWordsInfo.length > i) ? prevWordsInfo[i] : WordInfo.EMPTY_WORD_INFO;
- }
+ mPrevWordsInfo = prevWordsInfo;
}
// Create next prevWordsInfo using current prevWordsInfo.
public PrevWordsInfo getNextPrevWordsInfo(final WordInfo wordInfo) {
- final WordInfo[] prevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
+ final int nextPrevWordCount = Math.min(Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM,
+ mPrevWordsInfo.length + 1);
+ final WordInfo[] prevWordsInfo = new WordInfo[nextPrevWordCount];
prevWordsInfo[0] = wordInfo;
- for (int i = 1; i < prevWordsInfo.length; i++) {
- prevWordsInfo[i] = mPrevWordsInfo[i - 1];
- }
+ System.arraycopy(mPrevWordsInfo, 0, prevWordsInfo, 1, prevWordsInfo.length - 1);
return new PrevWordsInfo(prevWordsInfo);
}
public boolean isValid() {
- return mPrevWordsInfo[0].isValid();
+ return mPrevWordsInfo.length > 0 && mPrevWordsInfo[0].isValid();
}
public void outputToArray(final int[][] codePointArrays,
@@ -129,6 +126,10 @@ public class PrevWordsInfo {
}
}
+ public int getPrevWordCount() {
+ return mPrevWordsInfo.length;
+ }
+
@Override
public int hashCode() {
return Arrays.hashCode(mPrevWordsInfo);